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 1407. One-two, One-two

To Admins
Posted by Ibragim Atadjanov (Tashkent U of IT) 24 Oct 2010 15:19
something wrong with the 1st test or tests
Following prog give me ans for all n (1..100)
but at first test it gave me TL

import java.math.BigInteger;
import java.util.Scanner;

public class Timus1407 {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String s = "2";
        BigInteger two = new BigInteger("2");
        for (int i = 2; i <= n; i++) {
            BigInteger bigInteger = two.pow(i);
            String tmp = "1" + s;
            if(new BigInteger(tmp).mod(bigInteger) == BigInteger.ZERO){
                s = tmp;
            }
            else{
                s = "2" + s;
                if(new BigInteger(s).mod(bigInteger) != BigInteger.ZERO){
                    for(;;){}
                }
            }
        }
        System.out.print(s);
    }
}
Re: To Admins
Posted by Sergey Lazarev (MSU Tashkent) 24 Oct 2010 18:31
Strange... On my computer it gives nothing except infinite running.
You shouldn't compare BigInteger with "==". Use "compareTo" method.
thanks stupid mistake
Posted by Ibragim Atadjanov (Tashkent U of IT) 25 Oct 2010 12:51
Strange but it is not tl in my computer. Its working still.