CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Jace
Submission time:2017-10-04 13:24:16 +0300
Language:Python3
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.11 s1details
#2ACCEPTED0.07 s2details
#3ACCEPTED0.12 s3details

Code

from math import log, ceil
from random import randint

queries = []

count = int(input())
for _ in range(count):
    queries.append(int(input()))

#for i in range(4):
#    print(len([_ for _ in range(1, 10000) if ceil(log(_, 10)) == i]))
#    print(ceil(log(10**i + 1, 10))*10**(i+1)*0.9 / (i+1))
#    print(ceil(log(10**i + 1, 10))*10**(i+1)*0.9)
#    print()

def group(x):
    i = 0
    c = 0
    while c + (i+1)*10**i*9 < x:
        c += (i+1)*10**i*9
        i += 1
    return i, c

##pos = 0
##
##ll = 1
##
##while True:
##
##    cc = ""
##    for i in range(max(10000*pos, 1), 10000*(pos+1)):
##        cc += str(i)
##
##    queries = [i for i in range(ll, ll+len(cc))]
##
##    ll += len(cc)
##    pos += 1
##
##    cc2 = ''
##
##    for query in queries:
##        #print('Q', query)
##        #print('C', cc[query-1])
##        #print('G', group(query))
##        if query < 10:
##            #print(query, end='')
##            cc2 += str(query)
##        else:
##            l, s = group(query)
##            s += 1
##            
##            #print(query - s,
##            #      (query - s)//(l+1),
##            #      10**l + (query - s)//(l+1),
##            #      (query - s) % (l+1))
##            #print(str(int(10**l + (query - s)//(l+1)))[int((query - s) % (l+1))], end='')
##            cc2 += str(int(10**l + (query - s)//(l+1)))[int((query - s) % (l+1))]
##            #print('?')
##
##    print(cc == cc2)
##    print(len(cc), len(cc2))
##    if not cc == cc2:
##        print(cc, cc2)
##        break
##    #print(cc, cc2)
##    #break

for query in queries:
    #print('Q', query)
    #print('C', cc[query-1])
    #print('G', group(query))
    if query < 10:
        print(query)
        #cc2 += str(query)
    else:
        l, s = group(query)
        s += 1
        
        #print(query - s,
        #      (query - s)//(l+1),
        #      10**l + (query - s)//(l+1),
        #      (query - s) % (l+1))
        print(str(int(10**l + (query - s)//(l+1)))[int((query - s) % (l+1))])
        #cc2 += str(int(10**l + (query - s)//(l+1)))[int((query - s) % (l+1))]
        #print('?')
    

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