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

Problem Description
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.

Give you n. Your task is to find g(n) modulo 264.

 
Input
The first line contains an integer T indicating the total number of test cases. Each test case is a line with a positive integer n.

1≤T≤20000
1≤n≤109

 
Output
For each test case, print one integer s, representing g(n) modulo 264.
 
Sample Input
2
6
514
 
Sample Output
26
328194
 
Source
 
题意:略
分析:http://blog.csdn.net/firstlucker/article/details/49336427
这篇题解不错。
下面说明:x的约数的欧拉函数的和 = x
即sigma(d|x, phi(d)) = x
因为对于所有1-x的数,与x的gcd必定为x的约数,设为d,那这样的数有多少?phi(x / d)个
又发现x/d也是x的约数,所以。。。
sigma(d|x, phi(d)) = sigma(d|x, phi(x/d)) = x
这篇题解最后一步用了约数和定理。
 
其代码中防溢出运算更是简单、机智的令人发指
 
 #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 = ;
bool Flag = ;
while(!(ch >= '' && ch <= ''))
{
if(ch == '-') Flag ^= ;
ch = getchar();
}
while(ch >= '' && ch <= '')
{
Ret = Ret * + ch - '';
ch = getchar();
}
return Ret;
} const int N = ;
int n;
int Prime[N], Tot;
bool Visit[N]; inline void GetPrime()
{
For(i, , N-)
{
if(!Visit[i]) Prime[++Tot] = i;
For(j, , Tot)
{
if(i * Prime[j] >= N) break;
Visit[i * Prime[j]] = ;
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 == )
{
puts("");
return;
} LL Total = , Except = n;
For(i, , Tot)
{
if(Prime[i] * Prime[i] > n) break;
if(!(n % Prime[i]))
{
int Fact = ;
LL Cnt = ;
while(!(n % Prime[i]))
{
Cnt *= Prime[i];
Fact++;
n /= Prime[i];
}
Except *= Fact;
Cnt *= Prime[i];
LL a = (Cnt - ) / (Prime[i] - ), b = Cnt + , c = Prime[i] + ;
Total *= ((a / c) * (b / c) * c + a % c * (b / c) + b % c * (a / c));
//cout << Total << ' ' << Except << endl;
}
} if(n > ) Except <<= , Total *= ( + 1LL * n * n);
cout << Total - Except << endl;
} int main()
{
SetIO("");
Input();
//Solve();
return ;
}

2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b的更多相关文章

  1. 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild

    Rebuild Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  2. 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building

    House Building Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) ...

  3. 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory

    Chip Factory Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  4. 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree

    Partial Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  5. 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me

    Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  6. 2015ACM/ICPC亚洲区长春站 F hdu 5533 Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  7. 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich

    Too Rich Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total ...

  8. HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array

    Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...

  9. HDU-5532//2015ACM/ICPC亚洲区长春站-重现赛-F - Almost Sorted Array/,哈哈,水一把区域赛的题~~

    F - Almost Sorted Array Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

随机推荐

  1. AspectJ报错:error at ::0 can't find referenced pointcut XXX

    今天在使用AspectJ进行注解切面时,遇到了一个错误. 切点表达式就是无法识别——详细报错信息如下: Exception in thread "main" org.springf ...

  2. navicat连接oracle报错ORA-12737: Instant Client Light: unsupported server character set CHS16GBK”

    原文如下http://blog.163.com/cp7618@yeah/blog/static/7023477720142154449893/?COLLCC=1318255100& 这个工具可 ...

  3. ubuntu上完全卸载package

    inux上完整的卸载apt方式安装软件的办法. 假设你的包叫做: your_pkg apt-get --purge remove your_pkg apt-get autoremove apt-get ...

  4. 【Hadoop】Hive HSQ 使用 && 自定义HQL函数

    4 HQL 4.1 官网 4.1.1 https://cwiki.apache.org/confluence/display/Hive/LanguageManual 4.1.2 性能调优 4.1.2. ...

  5. Java异常的栈轨迹fillInStackTrace和printStackTrace的用法

    本文转自wawlian 捕获到异常时,往往需要进行一些处理.比较简单直接的方式就是打印异常栈轨迹Stack Trace.说起栈轨迹,可能很多人和我一样,第一反应就是printStackTrace()方 ...

  6. 【转】基于LDA的Topic Model变形

    转载自wentingtu 基于LDA的Topic Model变形最近几年来,随着LDA的产生和发展,涌现出了一批搞Topic Model的牛人.我主要关注了下面这位大牛和他的学生:David M. B ...

  7. 《转》常用Petri网模拟软件工具简介

    本文转载自liusj2003,如给您带来不便之处,请联系博主. 首先要介绍的的一个非常有名的Petri 网网站--Petri Nets World: http://www.informatik.uni ...

  8. php-fpm 进程管理

    2015年2月26日 15:40:15 先查找 PHP-FPM 的进程号 ps -ef | grep php-fpm root Feb12 ? :: php-fpm: master process ( ...

  9. ts tp 高清播放软件 Elecard MPEG Player 6.0.130827

    Elecard MPEG Player 6.0.130827 计算机配置不高的情况下,流畅播放高清视频. 缺点是搜索时停顿严重. 包里有注册机. 下载地址 http://pan.baidu.com/s ...

  10. HDU 2147 kiki's game(博弈)

    kiki's game Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Submit S ...