fork download
  1. def gcd(m,n):
  2. while m>0 and n>0:
  3. if m < n :
  4. n = n % m
  5. else:
  6. m = m % n
  7. return m + n;
  8.  
  9. primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67 ]
  10.  
  11. def cnt(n,m,k):
  12. g = gcd(n,m)
  13. total = 1
  14.  
  15. for i in range(19):
  16. if g <= 1: break
  17. l = 0
  18. while g%primes[i] == 0:
  19. g = g // primes[i]
  20. l = l + 1
  21. total = total * (l+1)
  22. return total == k
  23.  
  24. n = int(input('n: '))
  25. k = int(input('k: '))
  26. count = 0
  27. for m in range(1,n):
  28. if cnt(n,m,k) != 0: count = count + 1
  29. print(count)
  30.  
  31.  
Success #stdin #stdout 0.02s 7448KB
stdin
5000
2
stdout
n: k: 1400