Bzoj-2705 Longge的问题 欧拉函数
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2705
题意: 求 sigma(gcd(i,n), 1<=i<=n<2^32)
只有一组数据,很好搞,答案就是sigma(phi(n/d)),直接搜就行了。
//STATUS:C++_AC_8MS_11284KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
//#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e15;
const int dx[]={-,,,};
const int dy[]={,,,-};
const int day[]={,,,,,,,,,,,,};
//Daily Use ...
inline int sign(double x){return (x>EPS)-(x<-EPS);}
template<class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> inline T lcm(T a,T b,T d){return a/d*b;}
template<class T> inline T Min(T a,T b){return a<b?a:b;}
template<class T> inline T Max(T a,T b){return a>b?a:b;}
template<class T> inline T Min(T a,T b,T c){return min(min(a, b),c);}
template<class T> inline T Max(T a,T b,T c){return max(max(a, b),c);}
template<class T> inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));}
template<class T> inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));}
//End LL p[N][];
LL ans,n,cnt; void dfs(LL d,LL phi)
{
if(d==cnt){
ans+=phi;
return ;
}
dfs(d+,phi);
phi=phi/p[d][]*(p[d][]-);
for(int i=;i<=p[d][];i++)
dfs(d+,phi);
} int main(){
// freopen("in.txt","r",stdin);
int i,j,la;
LL t;
scanf("%lld",&n);
cnt=;
for(t=n,i=;i*i<=t;i++){
if(t%i==){
p[cnt][]=i;
while(t%i==){
p[cnt][]++;
t/=i;
}
cnt++;
}
}
if(t)p[cnt][]=t,p[cnt][]=,cnt++; ans=;
dfs(,n); printf("%lld\n",ans);
return ;
}
Bzoj-2705 Longge的问题 欧拉函数的更多相关文章
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- 【bzoj2705】[SDOI2012]Longge的问题 欧拉函数
题目描述 Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). 输入 一个整数,为N. 输出 ...
- poj 2480 Longge's problem [ 欧拉函数 ]
传送门 Longge's problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7327 Accepted: 2 ...
- bzoj 2190 [SDOI2008]仪仗队(欧拉函数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2190 [题意] n*n的正方形,在(0,0)格点可以看到的格子数目. [思路] 预处理 ...
- bzoj 1408 [Noi2002]Robot(欧拉函数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1408 [题意] 求m的所有约数中,满足可以分解成(奇数个不同素数/偶数个不同素数/其 ...
- Bzoj 2818: Gcd 莫比乌斯,分块,欧拉函数,线性筛
2818: Gcd Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 3241 Solved: 1437[Submit][Status][Discuss ...
- BZOJ2705: [SDOI2012]Longge的问题(欧拉函数)
题意 题目链接 Sol 开始用反演推发现不会求\(\mu(k)\)慌的一批 退了两步发现只要求个欧拉函数就行了 \(ans = \sum_{d | n} d \phi(\frac{n}{d})\) 理 ...
- BZOJ 2818 GCD 素数筛+欧拉函数+前缀和
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2818 题意:给定整数N,求1<=x,y<=n且Gcd(x,y)为素数的数对( ...
- 【BZOJ】2818: Gcd(欧拉函数+质数)
题目 传送门:QWQ 分析 仪仗队 呃,看到题后感觉很像上面的仪仗队. 仪仗队求的是$ gcd(a,b)=1 $ 本题求的是$ gcd(a,b)=m $ 其中m是质数 把 $ gcd(a,b)=1 $ ...
随机推荐
- 移动web开发入门级
http://www.infoq.com/cn/articles/development-of-the-mobile-web-deep-concept/
- hdu 4664 Triangulation 博弈论
看到这题时,当时还不会做,也没搞懂sg函数,于是狠狠的钻研了下博弈论,渐渐的知道了sg函数…… 现在在来做这题就很容易了,1A 打表容易发现在80左右的时候就出现循环节了 代码如下: #include ...
- http://jingyan.baidu.com/article/a378c960630e61b329283045.html
http://jingyan.baidu.com/article/a378c960630e61b329283045.html
- [topcoder]AvoidRoads
二维动态规划.和某一道leetcode的题目差不多.就是多了blocks的数组或集合. 本次解题的心得有:1.根据题意使用集合表示阻碍:2.使用字符串的形式表示整数的pair,简洁明了:3.p1到p2 ...
- dup和dup2函数以及管道的实现
疑问:管道应该不是这样实现的,因为这要求修改程序的代码 dup和dup2也是两个非常有用的调用,它们的作用都是用来复制一个文件的描述符.它们经常用来重定向进程的stdin.stdout和stderr. ...
- TOP命令详解
TOP是一个动态显示过程,即可以通过用户按键来不断刷新当前状态.如果在前台执行该命令,它将独占前台,直到用户终止该程序为止.比较准确的说,top命令提供了实时的对系统处理器的状态监视.它将显示系统中C ...
- 锋利的JQuery-认识Jquery
今天开始学习菜鸟的JQuery,这本书在一前看过一遍了,但是由于虽然看了,但是将近一年在工作中基本上没有用上,很是悲催,菜鸟想,用一到两个星期时间把这本书看一遍吧.就像菜鸟前面的jsdom一样,菜鸟写 ...
- 为Windows 7添加“Internet打印”功能
http://wangchunhai.blog.51cto.com/225186/1156589/
- Oracle DBA常用SQL
监控SQL 1.监控事例的等待: select event,sum(decode(wait_time,0,0,1)) prev, sum(decode(wait_time,0,1,0)) curr,c ...
- Ruby Gem命令
Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找.安装.升级和卸载软件包,非常的便捷. Ruby 1.9.2版本默认已安装Ru ...