Can someone please help why is the below code so inefficient.
Thanks in Advance.
#define ll long long int
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
boost_io;
int t;
cin>>t;
while(t-->0){
ll k, s=0;
cin>>k;
int d0, d1;
cin>>d0>>d1;
if(k==2){
s=d0+d1;
}
else{
int d=(d0+d1)%10;
s+=d0+d1+d;
int h=3;
int ha[4];
ha[0]=0;ha[1]=4;ha[2]=12;ha[3]=18;
for(;h<=k;){
d=(2*d)%10;
if(d!=4){
s+=d;
h++;
}
else{
break;
}
}
s+=((k-h)/4)*20+ha[(k-h)%4];
}
if(s%3==0){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
return 0;
}
Thanks Again.