CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Minna Vuorinen
Submission time:2017-10-11 19:57:23 +0300
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.21 s1details
#20.28 s2details
#3--3details

Code

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

public class kyselyt {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int amountOfCases = Integer.parseInt(in.nextLine());
		for (int i = 0; i < amountOfCases; i++) {
			System.out.println(performFunction(new BigInteger (in.nextLine())));
		}
		in.close();
	}

	public static BigInteger performFunction (BigInteger position) {
		int j = 0;
		for (j = 0; ((9 * (j + 2) * (int) Math.pow(10, j + 1) - (int) Math.pow(10, j + 2) + 2) / 9) < position.intValue(); j++);
		BigInteger length = new BigInteger(String.valueOf(j));
		position.subtract(BigInteger.valueOf((9 * (length.intValue() + 1) * ((int) Math.pow(10, length.intValue())) - ((int) Math.pow(10, length.intValue() + 1)) + 1) / 9)); 
		BigInteger number = BigInteger.valueOf((int) Math.pow(10, length.intValue() - 1)  + (position.intValue() - 1) / length.intValue());
		return BigInteger.valueOf((position.intValue() % length.intValue() == 0) ? number.intValue() % 10 : (number.intValue() / ((int) Math.pow(10, length.intValue() - position.intValue() % length.intValue()))) % 10);
	}

}

Test details

Test 1

Group: 1

Verdict:

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
0
6
7
4
9
...

Error:
Exception in thread "main" java.lang.ArithmeticException: / by zero
	at kyselyt.performFunction(kyselyt.java:19)
	at kyselyt.main(kyselyt.java:9)

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
3
9
9
6
2
...

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)