ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1131. Copying

Time limit! please help
Posted by Gregory 23 Feb 2013 18:23
import java.util.Scanner;

public class Computers {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = 0;
        int com = in.nextInt();
        int mod = in.nextInt();

        if (mod == 1 && com == 1 ){
            System.out.println(mod);
            return;
        }

        for(int x = 1;x < com;){
            if (x == 1){
                x++;
                a++;
            }
            if (x - mod == 0 && com - x > mod){
                x+=mod;
                a++;
            }else if (x - mod == 0 && com - x < mod){
                x+= com - x;
                a++;
            }
            if (x < mod && com - x > mod){
                x+=x;
                a++;
            }else if (x < mod && com - x < mod){
                x+= com - x;
                a++;
            }
            if (x > mod && com - x > mod){
                x+=mod;
                a++;
            }else if (x > mod && com - x < mod){
                x+= com - x;
                a++;
            }

        }
        System.out.println(a);
    }

}