Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import random
  2. import math
  3.  
  4. x=8
  5. y=2
  6. N=3
  7. def modexp(x,y,N):
  8. if (y==0):
  9. return 1
  10. z= modexp(x,(y/2),N)
  11. if y%2 == 0:
  12. return (z*z)%N
  13. else:
  14. return (x*z*z%N)
  15. print (modexp(8,3,3))
  16.  
  17. def primality2(N,k):
  18. y = N-1
  19. for i in range (0,k):
  20. x = random.randint(2, N-1)
  21. ##print x
  22. if modexp(x,y,N) !=1:
  23. return "not prime"
  24. return "prime"
  25.  
  26. count = 0
  27. for i in range (0,1000):
  28. result = primality2(1729,10000)
  29. if result == "prime":
  30. count +=1
  31. print count
  32.  
  33. Given inputs N and k, you should determine whether N is prime or not using k trails. Print N "is prime" or N "is not prime".
  34. Part 2
  35.  
  36. Carmichael numbers are composite numbers that pass fermat's little theorem for all integers aa relatively prime to NN. For each of the following Carmichael numbers determine the probability of failure in k trials, using k=1000. That is, the probability that the number is determined to be a prime when in fact it is not.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement