CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Leiska
Submission time:2017-10-05 18:05:05 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int nthdigit(longl)':
input/code.cpp:12:11: error: declaration of 'longl k' shadows a parameter
     longl k, n, x, p, m = 1, s = 0;
           ^

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 k, n, x, p, m = 1, s = 0;
    
	cin >> k ;
	
    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;
    }
}