CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:SeveriK
Submission time:2017-10-05 22:40:45 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.33 s1details
#2ACCEPTED0.39 s2details
#3ACCEPTED0.39 s3details

Code

import java.util.*;
import java.math.*;

public class TestClass {
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        
        int q = input.nextInt();
    	for (int i = 0; i < q; i++)
    	{
    		BigInteger k = input.nextBigInteger();

    		int a = 0;
    		BigInteger gCeiled = new BigInteger("0");

    		BigInteger result = new BigInteger("0");

    		int o = 1;
    		Boolean done = false;
    		while (!done)
    		{
    			BigInteger temp = new BigInteger("10");
    			BigInteger oTimes9 = new BigInteger(String.valueOf(o * 9));
    			gCeiled = gCeiled.add(oTimes9.multiply(temp.pow(o - 1)));
    			if (gCeiled.compareTo(new BigInteger(String.valueOf(k))) == 1)
    			{
    				a = o;
    				done = true;
    			}
    			o++;
    		}

    		BigInteger temp = new BigInteger("0");
    		temp = (gCeiled.subtract(k));
    		BigInteger bigA = new BigInteger(String.valueOf(a));
    		BigInteger power = new BigInteger("10");
    		power = power.pow(a);
    		power = power.subtract(new BigInteger("1"));
    		result = power.subtract((temp.divide(bigA)));

    		BigInteger mod = (gCeiled.subtract(k)).mod(bigA);
    		String digits = result.toString();

            System.out.println(digits.charAt(digits.length() - Integer.parseInt(mod.toString()) - 1) + "\n");
    	}
    }
}

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
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
1

2

3
...
Truncated

Test 3

Group: 3

Verdict: ACCEPTED

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
7

2

2
...
Truncated