[luoguP1069] 细胞分裂(数论)
Posted 蒟蒻zht的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[luoguP1069] 细胞分裂(数论)相关的知识,希望对你有一定的参考价值。
分解质因数,不说了
这题坑了我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; }
以上是关于[luoguP1069] 细胞分裂(数论)的主要内容,如果未能解决你的问题,请参考以下文章