fork(1) download
  1. #include <iostream>
  2. #define MOD 1000000007
  3. using namespace std;
  4.  
  5. int main() {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. long long n,t,d,hash,temp,tempn,digit,carry,add,temp_digit=0,digsum=0;
  11. cin>>n>>d;
  12. long long no=0;
  13. temp=n;
  14. while(temp--)
  15. {
  16. no=no*10+d;
  17. }
  18. temp=no*d;
  19. //cout<<temp;
  20. hash=0;
  21. tempn=n;
  22. add=0;
  23. carry=0;
  24. digit=0;
  25. while(tempn--)
  26. {
  27. temp_digit=temp%10;
  28. temp=temp/10;
  29. digsum=digsum+temp_digit;
  30. add+=temp_digit+carry;
  31. if(add>=10)
  32. {
  33. digit=add%10;
  34. carry=add/10;
  35. }
  36. else{
  37. digit=add;
  38. carry=0;
  39. }
  40. //cout<<digit<<" ";
  41. hash=(23*hash+digit)%MOD;
  42. }
  43. digsum=digsum+temp;
  44. tempn=n;
  45. temp=no*d;
  46. while(tempn--)
  47. {
  48. temp_digit=temp%10;
  49. temp=temp/10;
  50. digsum-=temp_digit;
  51. if((digsum+carry)>=10)
  52. {
  53. digit=(digsum+carry)%10;
  54. carry=(digsum+carry)/10;
  55. }
  56. else{
  57. digit=digsum+carry;
  58. carry=0;
  59. }
  60.  
  61. if(digsum!=0)
  62. {
  63. //cout<<digit<<" ";
  64. hash=(23*hash+digit)%MOD;
  65. }
  66. //cout<<hash<<" ";
  67. }
  68. cout<<hash<<endl;
  69. }
  70. return 0;
  71. }
Success #stdin #stdout 0s 3460KB
stdin
3
1 4
3 6
3 5
stdout
139
40079781
32745632