最小公倍数 SRM 661 Div1 250: MissingLCM

vector<int> get_primes(int N){// Sieve of Erathostenes to find all the necessary prime numbers:vector<int> res;vector<bool> composite(N + 1, false);for (int p = 2; p <= N; p++) {if (! composite[p]) {for (int i = p+p; i <= N; i += p) {composite[i] = true;}res.push_back(p);}}return res; } int get_exponent(int x, int p){int r = 0;while (x % p == 0) {r++;x /= p;}return r;} int getMin(int N){int res = 2;// For each prime number <= N:for (int p: get_primes(N) ) {// first find the maximum exponent of p among numbers <= N// (in the explanation , this max_exp is c)int max_exp = 0;int i = p;while (i <= N) {max_exp = std::max(max_exp, get_exponent(i,p) );i += p;}// seek the minimum i such that get_exponent(i,p) >= max_exp:while (get_exponent(i,p) < max_exp) {i += p;}// the maximum for all ps is the result:res = std::max(res, i);}return res;}

,但要相信真诚的爱情,对爱情永远怀有单纯的向往。

最小公倍数 SRM 661 Div1 250: MissingLCM

相关文章:

你感兴趣的文章:

标签云: