Need help in implementation with very large numbers

Problem : CodeChef: Practical coding for everyone
My code is not giving any answer in the 3rd test case of the problem.
I want to know what can be done to avoid memory overflow

My Code :

  #include <bits/stdc++.h>
  using namespace std;

 int main()
{
ios::sync_with_stdio(0);
cin.tie(0);


int t; cin >>t;
while(t--)
{
    long long int k,d0,d1;
    cin >> k >> d0 >> d1;
    long long int ans = d0 + d1;
    long long int m = ans;
    long long int n = pow(10,k-1)*d0 + pow(10,k-2)*d1;
    
    k = k-2;
    
    while(k!=0)
    {
        n += pow(10,k-1)*ans;
        ans+= ans;
        ans = ans%10;
        k--;
    }
    
    cout <<n << endl;
}

return 0;
}

what are constraints?

1 ≤ T ≤ 1000
2 ≤ K ≤ 1012
1 ≤ d0 ≤ 9
0 ≤ d1 ≤ 9

… by which he means 10^{12} :slight_smile: (the proper constraints are all on the linked Problem page).

This approach is a dead end, and you need a much more sophisticated one: the Editorial is here.

1 Like

thanks for your reply. I always get your reply whenever I ask doubts… Thanks a lot for your efforts

1 Like