fork(2) download
  1. /*
  2.  Shahadat Hossain
  3.  I.C.T Department
  4.  Comilla University
  5.  Session: 2013-2014
  6.  */
  7.  
  8. #include<bits/stdc++.h>
  9. using namespace std;
  10. typedef long long ll;
  11.  
  12. #define modulo 1000000007
  13. #define inverse 500000004 // modInverse(2)
  14.  
  15. ll bigMultiple(ll n, ll p){
  16. if(p == 0)
  17. return 0;
  18. else if(p%2 == 1){
  19. ll x = bigMultiple(n, p - 1);
  20. x %= modulo;
  21. ll y = n%modulo;
  22. return (x+y)%modulo;
  23. }
  24. else{
  25. ll x = bigMultiple(n, p/2);
  26. x %= modulo;
  27. return (x+x)%modulo;
  28. }
  29. }
  30.  
  31. ll sum(ll n){
  32. ll temp;
  33. temp = bigMultiple(n, n+1); // গুন না করে bigMultiple করেছি, এটা মূলত গুণ করতেছেে
  34. temp = bigMultiple(temp, inverse); // ২ এর মড্যুলার ইনভার্স বের করে গুণ করতেছি
  35. return temp;
  36. }
  37.  
  38. ll fun(ll n, ll mod){
  39. ll temp = sum(mod-1);
  40. ll t2 = n/mod;
  41. t2 = bigMultiple(t2, temp);
  42.  
  43. ll t3 = n%mod;
  44. t3 = sum(t3);
  45. return (t2+t3)%modulo;
  46. }
  47.  
  48. int main(){
  49.  
  50. ll a, b, mod;
  51. scanf("%lld %lld %lld", &a, &b, &mod);
  52.  
  53. a = fun(a - 1, mod);
  54. b = fun(b, mod);
  55.  
  56. ll res = b - a;
  57. if(res < 0)
  58. res += modulo;
  59. printf("%lld\n", res);
  60.  
  61. }
Success #stdin #stdout 0s 15232KB
stdin
199518197470727746 610061924367437027 644811579442798387
stdout
303799422