EIGHTS - Triple Fat Ladies

Pattern Matchers have been designed for various sorts of patterns. Mr. HKP likes to observe patterns in numbers. After completing his extensive research on the squares of numbers, he has moved on to cubes. Now he wants to know all numbers whose cube ends in 888.

Given a number k, help Mr. HKP find the kth number (indexed from 1) whose cube ends in 888.


The first line of the input contains an integer t, the number of test cases. t test cases follow.

Each test case consists of a single line containing a single integer k (1 <= k <= 2000000000000).


For each test case, output a single integer which denotes the kth number whose cube ends in 888. The result will be less than 263.




hide comments
amitnsky: 2018-08-16 11:04:24

reason behind AP is that we need some number after adding that last three digits should not disturbed of 192^3.
Let no is some x.
(192+x)^3 = 192^3 (have last 3 digits 888) + x^3 + 3 * 192 * x ( x+ 192 ).
to have last 3 digits of cube of 192 + x , x^3 should have last 3 digits 0 as well of 3 * 192 * x,
from this x^3, it is clear that x should be some multiple of 10.
from this 3 * 192 * x = 576 * x , x could be 1000 or factor of 1000 so that 576 * x always has 000 in its end. so the smallest factor of 1000 whose product with 576 has 000 at end is 250. so the ans is 250.

bansalabhi_98: 2018-06-27 09:00:44

@sreejoy4242 why separate case for k==1

bansalabhi_98: 2018-06-27 08:55:31

getting wrong answer using simple maths

jeet9: 2018-06-09 19:30:53

The test case may be long.

Last edit: 2018-06-09 19:31:32
wrzoboo: 2018-06-04 14:21:39

first run a bruteforce program to print you the first few elements of the sequence (using string manipulation). notice pattern, get ac in 7 lines (or less)

davisk83: 2018-05-31 11:21:42


iamnotsanju: 2018-04-06 20:57:47

can anyone tell me how to figure out that the numbers will be in AP?.
if you can please e-mail me at sanjib.sah@yahoo.com
Thank You :)

jmr99: 2018-03-11 11:21:18

good observation!!
if k==1

Last edit: 2018-03-11 11:21:53
riyadhrazzaq: 2018-03-09 15:07:54

There should be another test case.
Thanks for suggesting arithmetic progression.

vikashumain: 2018-03-06 11:57:34

Total time waste

Added by:Matthew Reeder
Time limit:1.197s
Source limit:30000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Al-Khawarizm 2006