2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
2015-11-04 20:11
357 查看
Count a * b
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 211 Accepted Submission(s): 116
[align=left]Problem Description[/align]
Marry likes to count the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0.
Let's denote f(m) as the number of ways to choose two non-negative integers a and b less than m to make a×b mod m≠0.
She has calculated a lot of f(m) for different m, and now she is interested in another function g(n)=∑m|nf(m). For example, g(6)=f(1)+f(2)+f(3)+f(6)=0+1+4+21=26. She needs you to double check the answer.
#include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <iostream> #include <map> #include <set> #include <algorithm> #include <vector> #include <deque> #include <queue> #include <stack> using namespace std; typedef long long LL; typedef double DB; #define MIT (2147483647) #define MLL (1000000000000000001LL) #define INF (1000000001) #define For(i, s, t) for(int i = (s); i <= (t); i ++) #define Ford(i, s, t) for(int i = (s); i >= (t); i --) #define Rep(i, n) for(int i = (0); i < (n); i ++) #define Repn(i, n) for(int i = (n)-1; i >= (0); i --) #define mk make_pair #define ft first #define sd second #define puf push_front #define pub push_back #define pof pop_front #define pob pop_back #define sz(x) ((int) (x).size()) #define clr(x, y) (memset(x, y, sizeof(x))) inline void SetIO(string Name) { string Input = Name + ".in"; string Output = Name + ".out"; freopen(Input.c_str(), "r", stdin); freopen(Output.c_str(), "w", stdout); } inline int Getint() { char ch = ' '; int Ret = 0; bool Flag = 0; while(!(ch >= '0' && ch <= '9')) { if(ch == '-') Flag ^= 1; ch = getchar(); } while(ch >= '0' && ch <= '9') { Ret = Ret * 10 + ch - '0'; ch = getchar(); } return Ret; } const int N = 40010; int n; int Prime , Tot; bool Visit ; inline void GetPrime() { For(i, 2, N-1) { if(!Visit[i]) Prime[++Tot] = i; For(j, 1, Tot) { if(i * Prime[j] >= N) break; Visit[i * Prime[j]] = 1; if(!(i % Prime[j])) break; } } } inline void Solve(); inline void Input() { GetPrime(); int TestNumber = Getint(); while(TestNumber--) { n = Getint(); Solve(); } } inline void Solve() { if(n == 1) { puts("0"); return; } LL Total = 1, Except = n; For(i, 1, Tot) { if(Prime[i] * Prime[i] > n) break; if(!(n % Prime[i])) { int Fact = 1; LL Cnt = 1; while(!(n % Prime[i])) { Cnt *= Prime[i]; Fact++; n /= Prime[i]; } Except *= Fact; Cnt *= Prime[i]; LL a = (Cnt - 1) / (Prime[i] - 1), b = Cnt + 1, c = Prime[i] + 1; Total *= ((a / c) * (b / c) * c + a % c * (b / c) + b % c * (a / c)); //cout << Total << ' ' << Except << endl; } } if(n > 1) Except <<= 1, Total *= (1 + 1LL * n * n); cout << Total - Except << endl; } int main() { SetIO("1002"); Input(); //Solve(); return 0; }
View Code
相关文章推荐
- 判断一个数是否在二维数组中
- 使用js脚本的好处以及其本身的特点
- R语言学习之数据的清理和转化
- Apriori algorithm---数据挖掘初学1
- maven之Nexus的配置【setting.xml里配置<profile>】(六)
- infobright源码安装
- 用JDK中的 jps、jinfo、jstat、jstack、jmap、jconsole等命令对JVM,内存,线程进行分析和故障诊断
- MFC函数启动执行过程
- 1104 冒泡排序语法树
- php把一个字符串分割成字符数组(可以用参数指定数组每个元素字符的长度)
- 设计模式六大原则(3)-依赖倒置原则
- Metal Framework基础使用教程
- 百度地图(基本定位和地理编码)
- 贝叶斯决策
- python json path xpath
- delphi richedit TopIndex
- Ubuntu下安装mysql和使用
- 阅读verilog程序总结
- 虚幻引擎 4.9
- 三个球的旋转的动画