There is n integer elements. Choose k elements then calculate their GCD, call result X.
What is maximal value of X?
k<=n<=3000, k<=100, elements in range 1..10^10.
Example:
3 2
120
36
100
Sample output
20
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
There is n integer elements. Choose k elements then calculate their GCD, call result X.
What is maximal value of X?
k<=n<=3000, k<=100, elements in range 1..10^10.
Example:
3 2
120
36
100
Sample output
20
Название |
---|
These constraints are in a very gray area, it really depends on the time limit. So depending on the limit you may or may not be able to:
Factor each number: Sieve of Eratosthenes + 3000 * (primes below 10 ^ 5) = 3000 * 10000; Generate divisors of each number in O(divisor_count). Divisor_count is at most 2300. Keep a frequency table for the divisors and just select the biggest one that's over k.
Just a first thought. It's a fragile solution, but it may very well work. Again, the constraints are too fuzzy. Will look for something cleaner and smarter though :).
If I correctly understood your solution it wouldn't work because the gcd can be a composite number instead of a prime.
I take in account all divisors, composite or not. The factoring into primes part is only so you can generate the divisors of a number quickly, instead of trying each number up to 10 ^ 5.
Thank you, I understood.
ez
gg easy FTFY