CSES - Datatähti 2017 alku - Results
Submission details
Task:Bittijono
Sender:lumieer
Submission time:2016-10-07 21:29:08 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.17 s1details
#2--2details
#3--3details

Code

//package bittijono;

import java.util.Scanner;

public class Bittijono {

    public static void main(String[] args) {
        final Scanner lukija = new Scanner(System.in);
        
        StringBuilder syotteet = new StringBuilder();
        
        int syotteidenMaara = lukija.nextInt();
        
        for (int a = 0; a <= syotteidenMaara; a++) {
            syotteet.append(lukija.nextLine());
        }     
        
        for (int o = 0; o < syotteet.length(); o++) { 
            long luku = Long.valueOf(syotteet.charAt(o));
        
             
            int pot = 0;
            //for (int i = 0; i < 10; i++) {
                pot = potenssi(luku);
                //System.out.println("pot " + pot);
                //System.out.println("Laskettavien maara: " + (luku - Math.pow(2, pot)));
                luku = (long) (luku - Math.pow(2, pot));
                //System.out.println("LUKU " + luku);
                //if (luku <= 10) {
                //    System.out.println("Valmis! " + pot);
                    //break;
                //}
                if (luku == 0) {
                    if (pot % 2 == 0) {
                        System.out.println("0");
                        return;
                    } else {
                        System.out.println("1");
                        return;            
                    }
                }
            //}

            StringBuilder jono = laskeBitteja(pot % 2, (int) luku);

            System.out.println(jono.charAt((int) (luku - 1)));
        }
    }
    
    public static StringBuilder laskeBitteja(int alku, int maara) {
        StringBuilder jono = new StringBuilder();
        //Luodaan nelinumeroinen jonon alku
        if (alku == 0) {
            jono.append("0110");
        } else {
            jono.append("1001");
        }
        //System.out.println(jono);   

        StringBuilder osa1 = new StringBuilder();
        StringBuilder osa2 = new StringBuilder();
        
        for (int i = 0; i < potenssi(maara) - 1; i++) {
            //Jaetaan jono kahteen osaan, ja lisataan ne jonoon
            osa1.append(jono.subSequence(jono.length() / 2, jono.length()));
            osa2.append(jono.subSequence(0, jono.length() / 2));
            
            //System.out.println("Jono " + jono);
            
            //System.out.println("OSA1 " + osa1);
            jono.append(osa1);
            
            //System.out.println("OSA2 " + osa2);
            jono.append(osa2);
            
            osa1.delete(0, osa1.length());
            osa2.delete(0, osa2.length());
        }
        
        return jono;
    }
    
    public static int potenssi(long syote) {
        
        double aiempi = syote * 1.0;
        int potenssi = 1;
        
        for (int i = 1; i <= 54; i++) {
            if (Math.pow(syote, 1.0 / i) - 2 >= 0 && Math.pow(syote, 1.0 / i) - 2 <= aiempi - 2) {
                aiempi = Math.pow(syote, 1.0 / i);
            } else {
                potenssi = i - 1;
                break;
            }
        }    
        return potenssi;
    }
}

Test details

Test 1

Group: 1

Verdict:

input
100
62
9
12
73
...

correct output
1
1
1
0
1
...

user output
0
1
1
0
1
...

Test 2

Group: 2

Verdict:

input
100000
565433
141881
120108
825392
...

correct output
1
1
0
0
1
...

user output
(empty)

Test 3

Group: 3

Verdict:

input
100000
374768524402011755
937067109466254318
389256426086302899
932585725667010169
...

correct output
0
1
1
1
1
...

user output
(empty)