https://www.codechef.com/GWC2021/problems/PH102

#include <iostream>

#include
#include
using namespace std;

int main() {
int a,b,t;
unsigned long long n,n1;
unsigned long sum=0, sum1;
n1 = pow(10,20);
cin>>t;
if(t>=1 && t<=1000){
for(int i=1;i<=t;i++){
cin>>n;
if(n>=1 && n<=n1){
sum1= to_string(n).length();
cin>>a>>b;
if(a>=1 && b>=1 && a<=100 && b<=100){
int j = sum1;
while(j>=1){
if(j%2==1)
sum = sum + a* (n%10);
else
sum = sum + b* (n%10);
n = n/10;
j–;
}
}
}
sum1=0;
while(sum>0 ||sum1>9){
if(sum ==0){
sum =sum1;
sum1=0;
}
sum1 += sum%10;
sum/=10;
}
cout<<sum1<<endl;
}
}

return 0;

}

At least bother to give some context and please format your code or share the submission link instead

4 Likes

I don’t no how but my keyboard freezed while posting this question(maybe being a newbie I messed things up)
my solution

here’s the link (thanks for replying)

HI Rashmi.
I want to clarify some things.
The conditions are just to make you aware of what is the domain of all possible values. You don’t need to check every value, like in your code.
If the problem statement reads t<=100 than that means t will be less than 100
Secondly you have 10^{20} in your code, which is very large and might cause Overflow error.
To combat that, use string to store the value

I highly suggest you read the AC solutions and then make modifications to your code .

1 Like

Worse than that: 10^20 is 10 xor 20 (=30), which is definitely not what we want :slight_smile:

3 Likes

Oh Yes, absolutely! :smile:

1 Like

Lol, @rashimishra , I think you are using tex in your code :laughing:.
You might want to use pow function and anyways I think it is not possible to fit 10^{20} in primitive data types.

1 Like

thanks for the reply Achal, I will try using string this time

Hi suman I corrected that code latter using the pow function and I still don’t get the 10^20 is 101010 xor 202020(=30=30=30) part :slightly_frowning_face:

Bitwise Operations

3 Likes

Yeah, so as said by @akshitm16 , ^ is bitwise xor operator in most of the languages.

3 Likes