-
October 31st, 2012, 11:12 AM
#1
Issue converting python code to c++
I am trying to solve a project euler prob 26 solution. I stumbled across a link that uses python to solve it. Here is the code snippet:
The IsPrime function is different which does not seem to cause any issues.
n = 997 #starting prime closest to limit
for p in range(n, 1 ,-2):
if not is_prime(p): continue
c = 1
while (pow(10, c) - 1) % p != 0:
c += 1
if (p-c) == 1: break
print "Answer to PE26 = ",p
I want to execute the same program on C++. But, the program does not complete(keeps on looping on the while loop below). I don’t know python that well. Can it be explained to me if the following code snippet is right in c++?
int p = 0;
int n = 997;
int c=0;
for ( p=n;p>1;p-2)
{
if(!IsPrime(p))
continue;
c=1;
while (((int)pow(10.0,c) – 1) % p != 0)
{
c += 1;
}
if (p-c==1)
break;
}
-
November 2nd, 2012, 01:18 AM
#2
Re: Issue converting python code to c++
Please post code in [code][/code] bbcode tags. This is especially important for Python code since indentation can be significant.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|