“C-number” is an integer n > 1 such that (b^n)mod n = b for all integers 1
Basically I have to create a program to run through about 2000 integers(1-2000), and have it satisfy the C-number condition, and then also check to see if it is NOT a prime number. I can’t seem to get the loop working correctly.
I have a program that creates a list of non primes, and a working program that if I input a number, it will return me that number if it is a c-number, if not I’ll get false returned.
I want it to just check numbers 1-2000 rather than just the one number I inputted, and then also check against the list of non prime numbers.
Here’s my code:
import numpy
def primesfrom2to(n):
""" Input n>=6, Returns a array of primes, 2 <= p < n """
sieve = numpy.ones(n/3 + (n%6==2), dtype=numpy.bool)
for i in xrange(1,int(n**0.5)/3+1):
if sieve[i]:
k=3*i+1|1
sieve[ k*k/3 ::2*k] = False
sieve[k*(k-2*(i&1)+4)/3::2*k] = False
return numpy.r_[2,3,((3*numpy.nonzero(sieve)[0][1:]+1)|1)]
num=range(600)
mylist =primesfrom2to(600)
s = [item for item in num if item not in mylist]
a=[]
d=[]
from math import *
def numc(n):
for a in range(1,n):
c= a**n
d=c%n
if a == d:
return n
else:
return False
print numc(561)
You probably need to just fix the indentation (needs fixing in a lot of places):
Python is pretty much written through indentation.