[luoguP1069] 细胞分裂(数论)
2024-08-30 13:25:52
分解质因数,不说了
这题坑了我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;
}
最新文章
- 一起学微软Power BI系列-官方文档-入门指南(3)Power BI建模
- 您不能在64位可执行文件上设置DEP属性
- android view:布局优化
- web攻防
- [SQL]oracle 的to_char、to_number、to_date用法
- 《C程序设计的抽象思维》1.9编程练习
- 神奇的fastcgi_finish_request
- Quartz 2D画虚线-b
- SQL的定义与使用
- 演示:纯CSS实现自适应布局表格
- (转)javaScript call 函数的用法说明
- TCP/IP-IP
- 标准简单SP模板(oracle)
- 关于Go语言共享内存操作的小实例
- MVC-Easy-UI-datagrid-分页-查询
- iOS_21团购_发送请求【点评】数据
- 微信小程序对医疗创业的启示,“餐饮+微信小程序”的猜想
- NGINX 配置404错误页面转向
- 在vue中使用css modules替代scroped
- 3;XHTML排列清单控制标记
热门文章
- macbookpro安装Ubuntu16.04.1 LTS爬坑之旅。亲测有效(集众家之长)。安装时间为2017-11-19。
- 认识 jQuery (第一笔 点出重点)
- P2668 斗地主 dp+深搜版
- python 模块-easygui.buttonbox
- 联想 Z5(L78011) 免解锁BL 免rec 保留数据 ROOT Magisk Xposed 救砖 ZUI 10.5.254
- mongo 3.4分片集群系列之一:浅谈分片集群
- oracle添加联合主键
- STA之Concepts (1)
- JSP学习笔记 - 内置对象 Response
- (转)淘淘商城系列——使用solrj来测试索引库