fork(4) download
  1. import sys
  2. from array import *
  3. p=[10000]
  4. def power(a,b,c):
  5. x=1
  6. y=a
  7. while(b > 0):
  8. if(b%2==1):
  9. x = (x*y)
  10. if x >=c:
  11. x = x%c
  12. y = (y*y)
  13. if y >=c:
  14. y = y%c
  15. b>>=1
  16. return x
  17. def main():
  18. tc=int(input())
  19. while(tc > 0):
  20. b,k,mod=input().split()
  21. b=int(b)
  22. k=int(k)
  23. mod=int(mod)
  24. for i in range(1,b+1):
  25. p.insert(i,power(i,k,mod))
  26. sum2=0
  27. for i in range(1,b+1):
  28. h=int(b/i)
  29. temp=p[i]*h
  30. #sys.stdout.write("%d "%(temp))
  31. if(temp>=mod):
  32. temp%=mod
  33. sum2+=temp
  34. if(sum2>=mod):
  35. sum2%=mod;
  36. ans=sum2
  37. print(ans)
  38. tc=tc-1
  39. main()
  40.  
Success #stdin #stdout 0.1s 10088KB
stdin
1
4 1 10000
stdout
15