您的位置:首页 > 其它

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: