CKWLK - Editorial

hey ! please help me in identifying the problem with this code. it works fine for all the test cases i tried but the verdict is still wrong ans.

(1zRMha - Online C++0x Compiler & Debugging Tool - Ideone.com)

Hey @lil_ninja !

You should print Yes and No
instead of YES and NO

Be careful from next time

Sudheera Y S
:slightly_smiling_face::smile:

1 Like

yes, sure

thanks a lot, thought about it a lot and now this being the error made me facepalm

why this giving wrong answer: CodeChef: Practical coding for everyone

1 Like

why tagging me in this code. also never send codes, share link. It makes it harder to scroll 100s of lines!

@line 39 YES \rightarrow Yes \implies AC

what is wrong in this code?

t= int(input())

def fun(n):
ans=0
if (n==10):
return 10
if(n==20):
return 20
if(n<10):
return 0
if (n>10 and n<20):
return 0
if(n%10==0 or n%20==0):
ans=ans+fun(n//20)+fun(n//10)
return ans

for i in range(t):
n= int(input())
ans=fun(n)

if(ans==10 or ans==20 or ans==30):
    print("Yes")
else:
    print("No")

I have also done this question by this method and it is accepted but not previous one

import math
t= int(input())
def Log2(x):
if x == 0:
return false;

return (math.log10(x) / 
        math.log10(2)); 

def isPowerOfTwo(n):
return (math.ceil(Log2(n)) ==
math.floor(Log2(n)));

for i in range(t):
n= input()
count=len(n)-len(n.rstrip(“0”))
a=n.rstrip(“0”)

if isPowerOfTwo(int(a)) and (count>=math.ceil(Log2(int(a)))):
    print("Yes")
else:
    print("No")

Editorialist’s solution was clearer though…

Check for n = 1
the answer is Yes but I think your code will give output No

So change this and it will work hopefully

Sudheera Y S
:slight_smile::smile:

Nice editorial

@vijju123 can you help me in this? seems like editorialist is busy.

if ans==30 it should print “No”

thanks, @raisinten can you help, why this logic giving the wrong answer

public class Test{

public static long by10(long temp){
       while(true){
           if(temp%10==0)
             temp = temp/10 ;
         else break ;
       }
       return temp ;

}

public static long by20(long temp){
    while(true){
           if(temp%20==0)
             temp = temp/20 ;
         else break ;
       }
       return temp ;
}

public static void main (String[] args){
      Scanner in = new Scanner(System.in);
      int t = in.nextInt();
      in.nextLine();
      for(int tc =0 ;tc<t;tc++){
      long n = in.nextLong();

       long a = by20(n);
       long b = by10(a);
       if(n<=1)System.out.println("No");
       else{
       if(b ==1)
        System.out.println("Yes");
       else{
          long c = by10(n);
          long d = by20(c);
          if(d==1)
            System.out.println("Yes");
          else
            System.out.println("No");

    }

     }

}

}
}

I feel both your solutions are correct. Your second solution assumes K \leq 10^6 which you should mention :stuck_out_tongue:

1 Like

yes. I am eager to know solution for K~10^12 or K~10^18(if exist) as editorialist mentioned. i am still noob in number theory.
Thanks

It won’t work because you’re assuming that the number N can be reduced greedily.

Did you give a thought to number 2000?

If we divide it greedily by 20 as long as possible, we are left with 5, which can’t be divided further by 20 or 10.

Let’s do this the other way round.

If we divide it greedily by 10 as long as possible, we are left with 2, which can’t be divided further by 20 or 10.

However, we can produce 2000 by the product of the sequence 10, 10 and 20.

Hope this helps. :slightly_smiling_face:

1 Like

It was only my guess that there “might” be some solution for K = 10^{12} or K = 10^{18} My solution too works up to K = 10^6 currently, will try for K = 10^{12}

2 Likes

I still think a recursive approach is so much easier.

My code is working in other IDE(like codeblocks,online compiler,C++shell) but not in codechef ide.Please help!!.Here is my code:
#include<bits/stdc++.h>
using namespace std;

int main()
{
int T;
cin>>T;
while(T–)
{long long int n,count=0;
cin>>n;
while((n%10)==0)
{n/=10;
count++;}
if(ceil(log2(n)) == floor(log2(n)) && count>=ceil(log2(n)))
cout<<“Yes”;
else
cout<<“No”;

}

}