fork download
  1. #include<stdio.h>
  2. #include<math.h>
  3. long long int power(int x,long long int y)
  4. {
  5. long long int temp;
  6. if( y == 0)
  7. return 1;
  8. temp = power(x, y/2);
  9. if (y%2 == 0)
  10. return temp*temp;
  11. else
  12. {
  13. if(y > 0)
  14. return x*temp*temp;
  15. else
  16. return (temp*temp)/x;
  17. }
  18. }
  19.  
  20. int main()
  21. {
  22.  
  23. int t;
  24. scanf("%d",&t);
  25. while(t--)
  26. {
  27. long long int n,d,carry=0,i,sum;
  28. scanf("%lld%lld",&n,&d);
  29. int arr[n+1];
  30. for(i=0;i<n;i++)
  31. {
  32. int s=d*d+carry;
  33. sum=s%10;
  34. carry=s/10;
  35. arr[i]=sum;
  36. if(i!=0)
  37. arr[i]+=arr[i-1];
  38. }
  39. arr[i]=carry+arr[i-1];
  40.  
  41. long long int m=2*n,res=0,t=0, f,fr,j=0,carry2=0;
  42. for(i=0;i<m;i++)
  43. {
  44. if(t<n)
  45. {
  46. f=arr[t];
  47. t++;
  48.  
  49. }
  50. else
  51. {
  52. f=arr[t]-arr[j];
  53. j++;
  54. }
  55. f=f+carry2;
  56. fr=f%10;
  57. carry2=f/10;
  58. printf("%lld\n",fr);
  59.  
  60. res+=(power(23,m-i-1)*fr)%1000000007;
  61. }
  62. printf("%lld\n",res%1000000007);
  63.  
  64. }
  65. return 0;
  66. }
  67.  
Runtime error #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
Standard output is empty