problem:
given at most 400 values of C. for each C,find an integer X (X<=10^18) such that 2^x mod (10^9 + 7) = c
i know that a value x must exist (X<10^9 + 7).but finding X is a problem for me. is there an efficient way to find x?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
problem:
given at most 400 values of C. for each C,find an integer X (X<=10^18) such that 2^x mod (10^9 + 7) = c
i know that a value x must exist (X<10^9 + 7).but finding X is a problem for me. is there an efficient way to find x?
Name |
---|
U can solve using shank baby step gaint step algorithm
To elaborate on teja349's answer, the idea is that there are at most m = 109 + 6 different values that 2x can take on, and if there is a solution to 2x = c, then you can write where and (modulo off-by-one errors).
All you have to do is compute all possible 2x values where and throw them in a hashtable, and then for each value of a, check if there is some element in the hashtable having value .