/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t–>0){
long k = sc.nextLong()-2;
long d0 = sc.nextLong();
long d1 = sc.nextLong();
long x = (d0+d1)%10,y=(d0+d1)%3;
if(k>7){
if(x==0){
k=0;
}
if(x==1){
k-=1;
y = (y+1+2*(k/4))%3;
}
else if(x==2){
y = (y+2*(k/4))%3;
}
else if(x==3){
k-=2;
y = (y+2*(k/4))%3;
}
else if(x==4){
k-=3;
y = (y+2*(k/4))%3;
}
else if(x==5){
k-=1;
y = (y+2)%3;
}
else if(x==6){
k-=1;
y = (y+2*(k/4))%3;
}
else if(x==7){
k-=4;
y = (y+1+2*(k/4))%3;
}
else if(x==8){
k-=2;
y = (y+2+2*(k/4))%3;
}
else if(x==9){
k-=3;
y = (y+2+2*(k/4))%3;
}
k%=4;
if(k==1 || k==3)
y = (y+2)%3;
}
else{
for(int i=0;i<k;i++){
y = (y+x)%3;
x = (x*2)%10;
}
}
if(y%3==0)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
can someone tell me what is the problem with this code.
Try sorting the budgets array.This way you can calculate the revenue that a price would generate in O(1) and by traversing over all the budgets (of the sorted budgets array) , you can choose the max_REVENUE.
I am struck at Mul of 3 question, please tell me if I am going in right direction.
As 8, 4, 2, 6 numbers would repeat after certain addition, like eg: for 13 8 1 ==> 8+1+9(after here numbers would repeat in order they started with 8)+8+6+2+4…etc. 8+4+2+6 = 20, so 13-3 = 10(excluding 8, 1, 9) → 10%4 =2(at last 2 digits 8, 6 would be left out). add all of them ==> ((10%4)*20)+(8+1+9)+(8+6) = 72==> 72%3 is true so print “YES”.
When i am trying to execute this problem in Codechef ide, i get time out whereas other ide works fine. How do i solve this problem?
hi i have followed steps of “MULTHREE” logic properly properly with referenct to c++ language but it is still saying incorrect. please help me out with this.and even i am getting the expected result in “MULTHREE” when i am hitting the code. please help me out where i am getting wrong.
For the Smartphone problem I sorted the array in ascending . so for the 2nd example I got {3,21,33,40,65} and my answer would be middle element times no. of elements after that (including it) i.e 99. similarly for the 1st example i would get {14,20,30,53} and the answer would be 30(middle element) *no.of elements after that. where am i wrong
Hey, for MULTHREE how does one recognize the powers of 2 pattern that went along with the hint 2 and hint 3. Are there any specific problems where the recurrence (of powers of 2) occurs?