al__nasim

icpc_preli_2017_i_repeated_digit_sum.cpp

Sep 27th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define read() freopen("C:\\Users\\HP NPC\\Documents\\cf\\code\\input.txt","r",stdin)
  3. #define write() freopen("C:\\Users\\HP NPC\\Documents\\cf\\code\\output.txt","w",stdout)
  4. using namespace std;
  5. int main()
  6. {
  7.     read();
  8.     write();
  9.     int tc;
  10.     cin>>tc;
  11.     for(int t=1;t<=tc;t++)
  12.     {
  13.         printf("Case %d: ",t);
  14.         string a, b;
  15.         cin>>a>>b;
  16.         int len_a = a.size();
  17.         int len_b=b.size();
  18.         long long sum_a=0;
  19.         for(int i =0;i<len_a;i++)
  20.         {
  21.             sum_a=1+ ((sum_a*10)%9+ (a[i]-'1')%9)%9;
  22.         }
  23.         //cout<<sum_a<<endl;
  24.         long long sum_b=0;
  25.         for(int i =0;i<len_b;i++)
  26.         {
  27.             sum_b = 1+((((sum_b*10)%6)+(b[i]-'1')%6)%6);
  28.         }
  29.         //cout<<sum_b<<endl;
  30.         long long res = 1+(((int)pow(sum_a,sum_b)-1)%9);
  31.         cout<<res<<endl;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment