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 | 3985 |
2 | jiangly | 3741 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3489 |
7 | Radewoosh | 3483 |
8 | Kevin114514 | 3442 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | atcoder_official | 162 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | nor | 150 |
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 .