hdu 6051 If the starlight never fade [欧拉函数] [2017 Multi-University Training Contest
来源:互联网 发布:淘宝导航二级下拉菜单 编辑:程序博客网 时间:2024/04/30 00:43
If the starlight never fade
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 104 Accepted Submission(s): 50
Problem Description
We will give you a non-negative integer m and a prime number p .
And we definef(i) is the number of pair(x,y) that satisfies (x+y)i≡xi%p and 1≤x≤p−1,1≤y≤m .
Now, you have to calculate the sum∑p−1i=1if(i) .
Maybe the sum is too big,so you only need to output the sum after mod1e9+7 .
And we define
Now, you have to calculate the sum
Maybe the sum is too big,so you only need to output the sum after mod
Input
The first line contains only one integer T , which indicates the number of test cases.
For each test case, there are a integerm(1≤m≤p−1) and a prime number p(2≤p≤1e9+7) on one line.
For each test case, there are a integer
Output
For each test case, output one line "Case #x: y", where x is the case number (starting from 1) and y is the sum after mod1e9+7 .
Sample Input
35 73 112 103
Sample Output
Case #1: 210Case #2: 390Case #3: 50388
题解 : http://bestcoder.hdu.edu.cn/blog/
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>#include<cmath>typedef long long ll;const int maxn = 1e5 + 10;const ll mod = 1e9 + 7;using namespace std;ll phi(ll n) { if(n == 1) return 2; ll ans = n; for(int i = 2; i * i <= n; i++) { if(n % i == 0) { ans -= ans / i; while(n % i == 0) n /= i; } if(n == 1) break; } if(n > 1) ans -= ans / n; return ans;}int main() { int m, t, p, vi = 1; scanf("%d", &t); while(t--) { scanf("%d %d", &m, &p); vector<int> v; int t = sqrt(p - 0.5); for(int i = 1; i <= t; i++) { if((p - 1) % i == 0) { v.push_back(i); if((p - 1) / i != i) v.push_back((p - 1) / i); } } ll ans = 0; for(int i = 0; i < v.size(); i++) { //printf("%d ", v[i]); ll g = (p - 1) / v[i]; g = g * phi(g) / 2; g %= mod; ans = (ans + ((ll)v[i] * v[i] % mod) * g) % mod; } //printf("\nans = %lld\n", ans); ans = ((ans - (ll)p * (p - 1) / 2) % mod + mod) % mod; ans = ans * m % mod; printf("Case #%d: %lld\n", vi++, ans); } return 0;}
阅读全文
0 0
- hdu 6051 If the starlight never fade [欧拉函数] [2017 Multi-University Training Contest
- HDU 6051 If the starlight never fade(原根+欧拉函数)
- HDU 3068 2017 Multi-University Training Contest
- HDU 6034 & 2017 Multi-University Training Contest
- hdu 6034 2017 Multi-University Training Contest
- HDU 3065 2017 Multi-University Training Contest
- HDU 6047 2017 Multi-University Training Contest
- HDU 6052 2017 Multi-University Training Contest
- HDU 6058 2017 Multi-University Training Contest
- HDU 6078 2017 Multi-University Training Contest
- 欧拉定理——PowMod ( HDU 5728 )(2016 Multi-University Training Contest 1 1006)
- HDU5728 2016 Multi-University Training Contest 1 (递归+欧拉函数)
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 2017 Multi-University Training Contest
- 这20个正则表达式,让你少写1,000行代码
- 后序遍历--CSU-ACM2017暑期训练4-dfs
- 解析给ImageView设置资源的五种方法
- 关于Android 4.4 后没有WRITE_SMS权限以及指定Android Studio2.3.3 SDK版本的问题
- centos7.3+hbase1.3.2集群安装
- hdu 6051 If the starlight never fade [欧拉函数] [2017 Multi-University Training Contest
- ZooKeeper Watch Java API浅析getData
- 扩展欧几里德与乘法逆元
- windows 时间同步服务器
- 在万网ECS服务器配置二级域名
- PhpStorm中一些实用的快捷键
- Qt中实现启动画面
- [leetcode]93. Restore IP Addresses
- 如何更改ubuntu的开机启动动画