hdu 5144 Frogs 数论
来源:互联网 发布:电影特效软件 编辑:程序博客网 时间:2024/04/25 03:36
这题的思路还是比较神奇的。
虽然ai的取值范围比较大但与m取gcd之后取值范围就缩小到m的因子范围内。
然后在把0到m-1的数,按与m的最大公约数分类
如果存在ai(与m取最大公约数之后的ai),
#include <bits/stdc++.h>#define pi acos(-1)#define pb push_back#define LL long long#define lson l , m , rt << 1#define rson m + 1 , r , rt << 1 | 1#define local freopen("in.txt","r",stdin)#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)using namespace std;const int MOD = 1e9 + 7;const int INF = 0x7FFFFFFF;const int MAX = 1000000;inline void read(int& x){ int flag = 1; char c; while(((c = getchar()) < '0' || c > '9') && c != '-'); c == '-' ? (flag = -1, x = 0) : (x = c - '0'); while((c = getchar()) >= '0' && c <= '9') { x = x * 10 + c - '0'; } x *= flag;}int fac[300],vis[300], cnt;int gcd(int a, int b){ return b ? gcd(b, a % b) : a;}int eular(int x){ int i, res = x; for(i = 2; i <= (int)sqrt(x); ++i){ if(x % i == 0){ res = res / i * (i - 1); while(x % i == 0) x /= i; } } if(x != 1) res = res / x * (x - 1); return res;}int main(){ int t, ca, n, i, j, tmp; LL m, ans; scanf("%d", &t); for(ca = 1; ca <= t; ++ca){ ans = 0; cnt = 0; memset(vis, 0, sizeof vis); scanf("%d%I64d", &n, &m); for(i = 1; i <= (int)sqrt(m); ++i){ if(m % i ==0){ fac[cnt++] = i; if(i * i != m) fac[cnt++] = m / i; } } sort(fac, fac + cnt); for(i = 0; i < n; ++i){ scanf("%d", &tmp); tmp = gcd(tmp, m); for(j = 0; j < cnt; ++j){ if(fac[j] % tmp == 0) vis[j] = 1; } } for(i = 0; i < cnt - 1; ++i){ if(vis[i]){ ans += m * eular(m / fac[i]) / 2; } } printf("Case #%d: %I64d\n", ca, ans); } return 0;}
总结:
ka%c==kb%c ,a为任意整数,b=gcd(a,c) (前面的等号是指他们的取值集合相同)- 一个常见的对整数集分类的方法,是按最大公约数数分类。
- 小于t且与t互质的数的和
=tϕ(t)÷2 ,由此可以猜想gcd(a,b)=gcd(a,a−b)
阅读全文
0 0
- hdu 5144 Frogs 数论
- HDU 5037 Frogs(数论)
- HDU 5514 Frogs (容斥+数论)
- HDU 5514 Frogs(欧拉函数+数论YY)
- Frogs(容斥+数论)
- Frogs HDU
- Frogs HDU
- hdu 5514 Frogs 2015沈阳区域赛 数论 欧拉 好题 开心的题
- HDU 5514 Frogs
- HDU 5514 Frogs
- HDU-5514 Frogs
- HDU 5514 Frogs
- hdu 5514 Frogs
- HDU-5514-Frogs
- HDU5514 Frogs(GCD+欧拉函数+数论)
- hdu 5514 Frogs(计数)
- hdu 5514 Frogs 容斥
- HDU Frogs 5514 容斥
- HDU
- EasyUI datagrid SpringMVC JPA 翻页功能实现
- oraecl导入导出数据
- linux(kali)开启ssh端口服务
- USACO-Section2.1 Sorting a Three-Valued Sequence [其他][排序][交换]
- hdu 5144 Frogs 数论
- 牛顿法与拟牛顿法学习笔记(四)BFGS 算法
- arcgis-“一个或多个已经添加图层的范围与关联空间参考不一致”“Arcmap不能绘制一个或者多个图层”
- 异常处理
- <Lisp面面观>松本行弘谈Lisp元编程
- Maven实战学习笔记2
- TX2系统安装
- 内存泄漏常见代码片段
- Golang plugin 插件例子