MULTIPLE OF 3

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll k,d0,d1,s,sum=0;
        cin>>k>>d0>>d1;
        ll x=(d0+d1)%10,d2=d0+d1;
        s=(2*x)%10+(4*x)%10+(8*x)%10+(6*x)%10;
        ll y=(k-3)%4,z=2;
        while(y!=0)
        {
            sum+=(z*x)%10;
            z=(z*2)%10;
            y--;
        }
        ll finalsum;
        finalsum=d0+d1+d2+s*((k-3)/4)+sum;
        if(finalsum%3==0)
        cout<<"YES"<<"\n";
        else
        cout<<"NO"<<"\n";
    }
    return 0;
}

can anyone tell me why my code gives TLE?

problem link:-CodeChef: Practical coding for everyone

  1. Format your code by enclosing it in triple backticks or share a link to your submission.
  2. Consider the case k=2. Here y=-1%4=-1 and the while loop becomes infinite.
1 Like

Thankyou so much