CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Leiska
Submission time:2017-10-05 18:05:25 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s2details
#3ACCEPTED0.07 s3details

Code

#include <iostream>
using namespace std;
typedef long long longl;

longl power(longl x, longl e) {
    if (e == 0) return 1;
    if (e == 1) return x;
    return x * power(x,e-1);
}

int nthdigit(longl k) {
    longl n, x, p, m = 1, s = 0;
	
    for(;;m++) {      
        if ( k-(s+(9*m*power(10,m-1))) < 1 ) break;
		s = s+(9*m*power(10,m-1));
    }
    
    n = (k - s);
    p = n % m;
    
    if( p==0 ) {
        x = ((power(10,m-1)) - 1) + (n/m);
        p = m;
    } else x = ((power(10,m-1)) - 1) + (1+((n-1)/m));
	
    p = -(p-(m+1));
    return ((x % power(10,p))/(power(10,p-1)));
}


int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
	
    int q; longl k; cin >> q;
    for(;q>0; q--) {
        cin >> k;
        cout << nthdigit(k) << endl;
    }
}

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
...
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
2
2
...
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
0
9
...
Truncated