标签:min tin efi sdi i++ 传送门 int include main
分解质因数,不说了
这题坑了我2个多小时
不熟悉位运算的优先级一定要加括号!!!!
#include <cstdio> #include <iostream> #define N 1000001 #define LL long long #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) int n, m1, m2, m, sum, ans = 1e9, tot, t = 1, p; int b[N], c[N]; bool f; inline int read() { int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == ‘-‘) f = -1; for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - ‘0‘; return x * f; } inline int gcd(int x, int y) { return !y ? x : gcd(y, x % y); } int main() { int i, j, a, x; n = read(); m1 = read(); m2 = read(); if(m1 == 1) { puts("0"); return 0; } x = m1; for(j = 2; j <= m1; j++) { while(!(x % j)) c[t] = j, b[t]++, x /= j; b[t] *= m2; if(b[t]) t++; } t--; for(i = 1; i <= n; i++) { sum = f = 0; p = 1; x = a = read(); if(gcd(m1, a) == 1) continue; for(j = 2; j <= a; j++) { tot = 0; while(!(x % j)) tot++, x /= j; if(tot && c[p] == j) sum = max(sum, b[p] / tot + (b[p] % tot != 0)), p++; if(c[p] < j) break; } if(p > t) ans = min(ans, sum); } printf("%d\n", ans == 1e9 ? -1 : ans); return 0; }
标签:min tin efi sdi i++ 传送门 int include main
原文地址:http://www.cnblogs.com/zhenghaotian/p/7056002.html