Submit | All submissions | Best solutions | Back to list |
IDC1948 - Identity crisis |
For every given number n we define x(n) as distance from n to the first number after n in form of 99...99. For example x(100)=899, x(45)=54, etc. Given several n numbers you have to find the Zp, where x(n) ≡ n (mod p).
Input
First line of input contains one number T (T < 20) - the number of test cases. In each of the next T lines contains one number each to represent n (0 < n < 30000000).
Output
In each line you have to write one number - the least p > 1 that x(n) ≡ n (mod p). If there is no such p the line should contain -1.
Example
Input: 2 234 5 Output: 3 -1
Explanation
x(234)=765. 765 mod 3=0, 234 mod 3=0 => 765 ≡ 234 (mod 3)
Added by: | Konrad Krystecki |
Date: | 2014-02-04 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
hide comments
|
|||||||
2014-02-07 16:19:31 Mitch Schwartz
@Mehmet Inal: I don't know if this is a spoiler (I'm trying to be vague), but you should be able to reduce the problem to something you know a lot about. :) |
|||||||
2014-02-07 14:45:11 mehmetin
Is there an O(1) solution for this? |
|||||||
2014-02-07 13:29:22 Mostafa 36a2
Ha ha ! the worst solution :D Who said do the math ;) |
|||||||
2014-02-07 12:58:05 Mostafa 36a2
@Pramod ans for 29999998 is 40000003 not -1 |
|||||||
2014-02-07 09:19:24 Pramod
@konrad krysteki: I don't understand why I am getting wrong answer. Here my program passed those test cases \n 234 --- 3 5 --- -1 3000000 ---- 3 200000 ---- 599999 1949959----13 2999999---41 29999999----53 please release more test cases...thanks Last edit: 2014-02-07 09:42:04 |
|||||||
2014-02-06 09:24:35 anurag garg
whooo AC in 0.00 Sec easy if you know the mathematics |
|||||||
2014-02-05 22:39:46 shiv prasad chabarval
@Konrad Krystecki please tell me why i m getting WA. my code is working for all test cases. is n>=0 ?? |
|||||||
2014-02-05 19:14:52 Bhavik
@lakshman: yes my code is also giving 599999..but still wa!! finally...got it Last edit: 2014-02-06 10:59:50 |
|||||||
2014-02-05 16:22:19 [Lakshman]
WFFFFF so many wrong answer but AC now. Last edit: 2014-02-06 13:46:42 |
|||||||
2014-02-05 11:42:18 Bhavik
and n>=0?? getting wa at 11th case.. Last edit: 2014-02-05 14:43:19 |