Task: | Kyselyt |
Sender: | Yytsi |
Submission time: | 2017-10-02 22:27:30 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 25 |
#3 | ACCEPTED | 63 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.03 s | 1 | details |
#2 | ACCEPTED | 0.05 s | 2 | details |
#3 | ACCEPTED | 0.04 s | 3 | details |
Code
#include <iostream>#include <string>using namespace std;typedef long long ll;ll tenPowerIndexes[17] = {10LL, 190LL, 2890LL, 38890LL, 488890LL,5888890LL, 68888890LL, 788888890LL,8888888890LL, 98888888890LL, 1088888888890LL, 11888888888890LL,128888888888890LL, 1388888888888890LL, 14888888888888890LL,158888888888888890LL, 1688888888888888890LL};ll customPow(ll base, ll exponent){if (exponent == 0LL) return 1LL;ll res = base;while (exponent != 1LL){res *= base;exponent--;}return res;}// This is a function that could generate the list <tenPowerIndexes>.void generatePowerIndexes(){ll prevSum = 0LL;for (ll i = 0LL; i < 17LL; i++){ll range = 9LL * customPow(10LL, i);ll digCount = i + 1LL;ll newSum = prevSum + (range * digCount);prevSum = newSum;tenPowerIndexes[i] = newSum + 1;}}ll howManyDigits(ll k){ll digits = 1LL;for (int i = 0; i < 17; i++){if (k < tenPowerIndexes[i]) break;else digits++;}return digits;}ll findDigit(ll k){if (k < 10LL) return k;ll d = howManyDigits(k);// d-space is now calculated.// Normalized index starting from the d-digit number.// ... 97 98 99 100 101 102 ...// For example, 100 will have the index 0 ==> p.ll p = k - tenPowerIndexes[d - 2];// Let's calculate what power of 10 digit are we trying to find (10**0, 10**1 etc).ll region = (d - 1) - (p % d);if (region == (d - 1)){// +1 required.return (p / (d * customPow(10LL, d - 1))) + 1;}return (p / (d * customPow(10LL, region))) % 10;}int main(){ios_base::sync_with_stdio(0);cin.tie(0);int q;cin >> q;cin.ignore();for (int i = 0; i < q; i++){ll search;cin >> search;cin.ignore();cout << findDigit(search) << "\n";}/*for (ll i = 10LL; i < 100LL; i++){char c = "0123456789"[findDigit(i)];cout << i << " : " << c << "\n";}*/return 0;}
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 |