CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Kisse
Submission time:2017-10-12 00:09:23 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.30 s1details
#2ACCEPTED0.28 s2details
#3ACCEPTED0.24 s3details

Code

import java.util.Scanner;

public class Kyselyt {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int q = input.nextInt();
        for (int i = 0; i < q; i++) {
            Long index = input.nextLong();
            if (index < 10) {
                System.out.println(index);
            }
            else {
                long base = 10;
                long len = 2;
                while (true) {
                    if (index < base) {
                        len = len - 1;
                        base = base - (9 * len * (long) Math.pow(10, len - 1));
                        break;
                    }
                    base = base + (9 * len * (long) Math.pow(10, len - 1));
                    len = len + 1;
                }
                //System.out.println("Base: " + base + ", Length: " + len);
                Long diff = (index - base);
                //System.out.println("Diff: " + diff);
                Long pos = (diff % len);
                //System.out.println("Position: " + (pos + 1) + "/" + len);
                Long step = len * (long) Math.pow(10, len - pos - 1);
                //System.out.println("Step: " + step);
                if (pos == 0) {
                    System.out.println((1 + Math.floorDiv(diff, step)) % 10);
                }
                else {
                    System.out.println((Math.floorDiv(diff, step)) % 10);
                }
            }
        }
    }
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
0
1
7
7
6
...

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
1
2
3
2
2
...

Test 3

Group: 3

Verdict: ACCEPTED

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
7
2
2
0
9
...