OJUMPS - Editorial

PROBLEM LINK:

Practice
Contest

Author: Dmytro Berezin
Tester: Sergey Kulik
Editorialist: Lalit Kundu

DIFFICULTY:

CAKEWALK

PREREQUISITES:

AD-HOC

PROBLEM:

Chef is at x=0.
1-jump: he will move from x -> x + 1
2-jump: he will move from x -> x + 2
3-jump: he will move from x -> x + 3
He will perform a lot of jumps in such a sequence: 1-jump, 2-jump, 3-jump, 1-jump, 2-jump, 3-jump, 1-jump, and so on.
Given an integer 0 ≤ a ≤ 1018, find will he ever arrive at a.

QUICK EXPLANATION:

In one sequence of 1-jump, 2-jump and 3-jump, he moves from x -> x + 6. So, if intermediate jumps are removed for a minute, x will always be a multiple of 6. Now, if we consider intermediate jumps, we will also consider points of form 6*k - 3, 6*k - 5.

Therefore,

a=input()    
if a%6==0 || a%6==1 || a%6==3:    
     print "yes"    
else:
     print "no"     

Complexity: O(1)

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution
Setter’s solution

1 Like

@admins: still waiting for the answer why there is compilation error for my JavaScript code - http://www.codechef.com/viewsolution/3813082

It works fine on IdeOne - http://ideone.com/yc3MFR

#include
using namespace std;
int main()
{
long a;
cout<<“enter value of a=”;
cin>>a;
if(((a%6)==0)||((a%6)==1)||((a%6)==3))
cout<<“yes”<<endl;
else
cout<<“no”<<endl;

    system("pause");
return 0;

}

you don’t have to print “Enter the value of a”.

I am assuming that you are asking why your code isn’t working!

Can someone tell me why my solution is coming as a wrong answer.
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

public static void main(String[] args) throws IOException {
        PrintWriter printWriter = new PrintWriter(System.out);
        double destination  = new Scanner(System.in).nextDouble();
        if (destination == 0) {
            printWriter.println("yes");
            
        } else {
            if (((destination + 5) % 6) == 0 || destination % 6 == 0 || ((destination+3) % 6) == 0) {
                printWriter.println("yes");
                printWriter.flush();
            } else {
                printWriter.println("no");
                printWriter.flush();
            }
        }
        printWriter.close();
}

}

Tip: One has to use the right size for the integer (long long in c++) in order to fit 18 digits.

https://www.codechef.com/viewsolution/18791814

I used the same logic. why still it gives WA?

@vivekshah1801 it took me 5 minutes to find the bug in your code. The bug is that the problem does not have any test cases!! You just have to take the number and show the output. I took care of this when I coded my solution but don’t know why it took so much time to find it in your code, lol.

https://www.codechef.com/viewsolution/20257191

Don’t know why I am getting a TLE… it’s working fine for me. I am using divisibility tests and char to int conversion. (I don’t want to use long long int.)