BZOJ 2705 [SDOI2012]Longge的问题 ——Dirichlet积
【题目分析】
狄利克雷卷积。

然后直接求出欧拉函数,计算和即可。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 500005
#define ll long long
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
}
int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int n;
int phi(int x)
{
// cout<<"phi"<<x;
int ret=x;
F(i,2,sqrt(x))
{
if (x%i==0) ret/=i,ret*=(i-1);
while (x%i==0) x/=i;
}
if (x>1) ret=ret/x*(x-1);
// cout<<" is "<<ret<<endl;
return ret;
}
ll ans=0;
int main()
{
Finout();
n=Getint();
F(i,1,sqrt(n)) if (n%i==0)
{
ans+=(ll)phi(i)*(n/i);
if (i*i<n) ans+=(ll)phi(n/i)*i;
}
cout<<ans<<endl;
}
BZOJ 2705 [SDOI2012]Longge的问题 ——Dirichlet积的更多相关文章
- BZOJ 2705: [SDOI2012]Longge的问题
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2554 Solved: 1566[Submit][ ...
- BZOJ 2705: [SDOI2012]Longge的问题( 数论 )
T了一版....是因为我找质因数的姿势不对... 考虑n的每个因数对答案的贡献. 答案就是 ∑ d * phi(n / d) (d | n) 直接枚举n的因数然后求phi就行了. 但是我们可以做的更好 ...
- BZOJ 2705: [SDOI2012]Longge的问题 [欧拉函数]
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 2553 Solved: 1565[Submit][ ...
- BZOJ 2705: [SDOI2012]Longge的问题 GCD
2705: [SDOI2012]Longge的问题 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnl ...
- bzoj 2705: [SDOI2012]Longge的问题 歐拉函數
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1035 Solved: 669[Submit][S ...
- Bzoj 2705: [SDOI2012]Longge的问题 欧拉函数,数论
2705: [SDOI2012]Longge的问题 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 1959 Solved: 1229[Submit][ ...
- [bzoj]2705: [SDOI2012]Longge的问题[数论][数学][欧拉函数][gcd]
[bzoj]P2705 OR [luogu]P2303 Longge的问题 Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需 ...
- bzoj 2705: [SDOI2012]Longge的问题——欧拉定理
Description Longge的数学成绩非常好,并且他非常乐于挑战高难度的数学问题.现在问题来了:给定一个整数N,你需要求出∑gcd(i, N)(1<=i <=N). Input 一 ...
- BZOJ 2705 [SDOI2012]Longge的问题(欧拉函数)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2705 [题目大意] 求出∑gcd(i,N)(1<=i<=N) [题解] $ ...
随机推荐
- 用python计算md5,sha1,crc32
Linux下计算md5sum,sha1sum,crc: 命令 输出 $md5sum hello f19dd746bc6ab0f0155808c388be8ff0 hello $sha1sum hel ...
- html base2
<html> <body> <h1>My First Web Page</h1> <p id="demo">A Para ...
- mybatis generator Date类型时间丢失
开篇 本次项目换用了Oracle数据库,讲真,真的不好用,不太喜欢,比较喜欢轻量级的MySQL但是不得不说从Oracle的严谨中学到不少好东西. <resultMap id="Base ...
- SGU_390_Tickets(另类数位DP)
Tickets Time Limit : 1000/500ms (Java/Other) Memory Limit : 524288/262144K (Java/Other) Total Subm ...
- 链表基础 HDU1267
基础的链表,模拟一下就好了...就签个到
- kill -QUIT <pid>
On Solaris and Linux a thread dump is also printed if the J2SE process receives a QUIT signal. So ki ...
- OGG 文档
[OGG]OGG的下载和安装篇 http://www.cnblogs.com/lhrbest/p/4564013.html [OGG]OGG的单向DML复制配置(一) http://www.cnblo ...
- ural1147 Shaping Regions
Shaping Regions Time limit: 0.5 secondMemory limit: 64 MB N opaque rectangles (1 ≤ N ≤ 1000) of vari ...
- Android-----View绘制流程以及invalidate()等相关方法分析 .
引自:http://blog.csdn.net/qinjuning/article/details/7110211 前言: 本文是我读<Android内核剖析>第13章----View工作 ...
- Wiegand协议(转)
源:http://blog.chinaunix.net/uid-22670933-id-3268318.html Wiegand26协议是由美国工业安全委员会SIA(Security Industry ...