Advertisement
Saleh127

UVA 10523

Oct 25th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. string multi(string nums1,string nums2)
  6. {
  7. int l1 = nums1.size();
  8. int l2 = nums2.size();
  9. string str( l1 + l2, '0');
  10. for(int i = l1-1; i >= 0; i--)
  11. {
  12. for(int j = l2-1; j >= 0; j--)
  13. {
  14. int p = (nums1[i]-'0')*(nums2[j]-'0') + (str[i+j+1]-'0');
  15. str[i+j+1] = p%10 + '0';
  16. str[i+j] += p/10;
  17. }
  18. }
  19. for(int i = 0; i < l1+l2; i++)
  20. {
  21. if(str[i]!= '0')
  22. {
  23. return str.substr(i);
  24. }
  25. }
  26. return "0";
  27. }
  28.  
  29. string addd(string a,string c)
  30. {
  31.  
  32. ll s1,s2,l,i,j,k=0;
  33. string sum="";
  34.  
  35. reverse(a.begin(),a.end());
  36. reverse(c.begin(),c.end());
  37.  
  38. s1=a.size();
  39. s2=c.size();
  40. l=max(s1,s2);
  41.  
  42. for(i=0; i<l; i++)
  43. {
  44. if(i<s1)
  45. {
  46. k+=(a[i]-'0');
  47. }
  48. if(i<s2)
  49. {
  50. k+=(c[i]-'0');
  51. }
  52. sum+=((k%10)+'0');
  53. k/=10;
  54. }
  55.  
  56. if(k)
  57. {
  58. sum+=(k+'0');
  59. }
  60. reverse(sum.begin(),sum.end());
  61.  
  62. for(i = 0; i <sum.size(); i++)
  63. {
  64. if(sum[i]!= '0')
  65. {
  66. return sum.substr(i);
  67. }
  68. }
  69. return "0";
  70. }
  71. int main()
  72. {
  73. ios_base::sync_with_stdio(0);
  74. cin.tie(0);cout.tie(0);
  75.  
  76.  
  77. ll a,d,e,i,j,k,l;
  78. string c;
  79. while(cin>>a>>c)
  80. {
  81. string x="1";
  82. string y="0";
  83. for(i=1;i<=a;i++)
  84. {
  85. string x="1";
  86. for(j=1;j<=i;j++)
  87. {
  88. x=multi(x,c);
  89. }
  90. x=multi(x,to_string(i));
  91. y=addd(y,x);
  92. }
  93. cout<<y<<endl;
  94. }
  95.  
  96. return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement