fork download
  1. # your code goes hereimport math
  2. import sys
  3. from fractions import gcd
  4.  
  5. try:
  6.  
  7. primos = []
  8. mcd = 0
  9. temp = 0
  10.  
  11. n = 100000000
  12. listaprimos = [True for i in range(n+1)]
  13. p = 2
  14.  
  15. while (p * p <= n): #revisa hasta raiz de n
  16.  
  17. # If prime[p] is not changed, then it is a prime
  18. if (listaprimos[p] == True):
  19.  
  20. # Update all multiples of p
  21. for i in range(p * p, n+1, p):
  22. listaprimos[i] = False
  23. p += 1
  24.  
  25. # Guardar numeros primos
  26. for p in range(2, n):
  27. if listaprimos[p]:
  28. primos.append(p)
  29. #print p,
  30.  
  31. while(1):
  32.  
  33. n = int(input())
  34. if(n == 0):
  35. break
  36. mcd = 0
  37.  
  38.  
  39. i = 0
  40.  
  41. while (i < len(primos)):
  42.  
  43. #print "Pase por aqui"
  44. #print "i: ",i
  45.  
  46. if(n%primos[i] == 0):
  47. #print "pren: ",n
  48. n = n // primos[i]
  49.  
  50. #print "postn: ",n
  51. temp += 1
  52. #print "temp: ",temp
  53.  
  54. else:
  55. i += 1
  56. if(temp != 0):
  57.  
  58. if(mcd == 0):
  59.  
  60. mcd = temp
  61. temp = 0
  62.  
  63. else:
  64.  
  65. mcd = gcd(temp, mcd)
  66. temp = 0
  67.  
  68.  
  69. if(mcd == 0):
  70.  
  71. print(1)
  72.  
  73. else:
  74.  
  75. print(mcd)
  76.  
  77.  
  78. except EOFError:
  79. exit
  80.  
Time limit exceeded #stdin #stdout 5s 3953152KB
stdin
17
1073741824
25
-17
-1073741824
-25
0
stdout
Standard output is empty