October 31st, 2012, 12:12 PM
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;
for ( p=n;p>1;p-2)
while (((int)pow(10.0,c) Ė 1) % p != 0)
c += 1;
November 2nd, 2012, 02:18 AM
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
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!