fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. unsigned long long int flr(long long int n, long long int i,long long int m)
  4. {
  5. unsigned long long int val = n /i ;
  6. unsigned long long int t = val % m ;
  7. return t;
  8.  
  9. }
  10.  
  11.  
  12.  
  13. int main ()
  14. {
  15.  
  16. unsigned long long int ans ,tot=2,k,n,m,i ;
  17. int t;
  18. scanf("%d",&t);
  19. while(t--)
  20. {
  21. scanf("%llu %llu",&n,&m);
  22. ans = 1 * flr(n,1,m);
  23. for(i=2;i<=n;i++)
  24. {
  25. k = i% m;
  26. ans =( (ans)%m + (((((k*k)%m*i)%m*i)%m)*(flr(n,i,m))%m )%m);tot++;
  27. }
  28. printf("%llu\n",ans);
  29. }
  30.  
  31.  
  32. }
  33.  
Success #stdin #stdout 0s 2296KB
stdin
1
4 1000
stdout
373