Need help in MULTHREE

I am getting wrong answer in MULTHREE, but can not find the test case which might fail, can anybody help please?

Here is my code:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int t;
    cin >> t;
    for(int i=0; i<t; i++){
        int long long k;
        int d0, d1;
        cin >> k >> d0 >> d1;
        int long long sum=d0+d1, units=(k-3)/4, leftover=(k-3)%4, last=(sum+(d0+d1)%10)%10;
        if(k==3){
            sum+=(d0+d1)%10;
        }
        else if(k>3){
            sum+=(d0+d1)%10+units*20;
            for(int j=0; j<leftover; j++){
                sum+=last;
                last=(last*2)%10;
            }
        }
        if(sum%3==0){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}

I haven’t thoroughly checked other details, but why haven’t you considered the case where K=2?

1 Like

Following are the cases where your program is giving wrong output:

4
9 4 6
8 3 2
7 6 4
167 181 479

Your Program Output:

YES
YES
YES
NO

Correct Output:

NO
NO
NO
YES
Look here only if you are not able to solve the problem on your own

If you are not able to find the bug after lot of trying, refer to the editorial here.

1 Like

Thank you very much! Got the problem.

I have initialized the value of sum as d0+d1 because the minimum value of k is 2. So when k=2, sum is already set to sum of the first 2 digits, anyways, I got the bug which was leading to wrong answer :+1: