HDU 3501 Calculation 2 ——Dirichlet积
【题目分析】
卷积太有趣了。

最终得出结论,互质数和为n*phi(n)/2即可。
计算(n*(n+1)/2-n-n*phi(n)/2)%md,用反正法即可证明。
【代码】
#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 md 1000000007
#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';
return x*f;
}
ll n;
ll phi(ll x)
{
ll t=x,upp=sqrt(x);
F(i,2,upp)
{
if (x%i==0) {t/=i;t*=i-1;}
while (x%i==0) x/=i;
}
if (x>1) t/=x,t*=x-1;
return t;
}
int main()
{
Finout();
while (scanf("%lld",&n)&&n)
cout<<(n*(n+1)/2-n-n*phi(n)/2)%md<<endl;
}
HDU 3501 Calculation 2 ——Dirichlet积的更多相关文章
- HDU 3501 Calculation 2(欧拉函数)
Calculation 2 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- HDU 3501 Calculation 2------欧拉函数变形
Calculation 2 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 3501 Calculation 2 (欧拉函数)
题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...
- hdu 3501 Calculation 2 (欧拉函数)
题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质 ...
- HDU 3501 Calculation 2
题目大意:求小于n的与n不互质的数的和. 题解:首先欧拉函数可以求出小于n的与n互质的数的个数,然后我们可以发现这样一个性质,当x与n互质时,n-x与n互质,那么所有小于n与n互质的数总是可以两两配对 ...
- 题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)
Description Given a positive integer N, your task is to calculate the sum of the positive integers l ...
- BZOJ 1101 [POI2007]Zap ——Dirichlet积
[题目分析] Dirichlet积+莫比乌斯函数. 对于莫比乌斯函数直接筛出处理前缀和. 对于后面向下取整的部分,可以分成sqrt(n)+sqrt(m)部分分别计算 学习了一下线性筛法. 积性函数可以 ...
- HDU——T 3501 Calculation 2
http://acm.hdu.edu.cn/showproblem.php?pid=3501 Time Limit: 2000/1000 MS (Java/Others) Memory Limi ...
- Calculation 2 HDU - 3501
https://vjudge.net/problem/HDU-3501 不会做啊...记一下做法 做法是计算小于n且与n互质的数的和:根据如果gcd(i,n)==1,那么gcd(n-i,n)==1,对 ...
随机推荐
- Loadrunner之脚本的调试和保存(六)
一.调试脚本 脚本录制完毕后,按F5键或单击菜单上的RUN按钮,可以运行脚本. 在VIRTUAL USER GENERATOR中运行脚本的作用,主要是查看录制的脚本能否正常通过,如果有问题 ...
- HDU 2102 A计划 经典搜索
A计划 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submissio ...
- CodeForces 429 B B. Working out
Description Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to loo ...
- js zhi网马
大家对木马都不陌生了,它可能要算是计算机病毒史上最厉害的了,相信会使木马的人千千万万,但是 有很多人苦于怎么把木马发给对方,现在随着计算机的普及,在网络上我相信很少有人会再轻易的接收 对方的文件了 ...
- PAT1014
Suppose a bank has N windows open for service. 一个银行有N个服务的窗口 There is a yellow line in front of the w ...
- APK反编译(Linux环境下)
先下载dex2jar和jd-gui这两个软件,然后解压APK,把解压出来的classes.dex,放到dex2jar的根目录,然后命令行进入到dex2jar根目录,然后执行命令 ./dex2jar ...
- 如何让struts2和servlet的共存
如何让struts2和servlet的共存 (2013-08-29 14:07:49) 转载▼ 标签: servlet与struts2共存 同时配置struts2与ser servlet访问不到 分类 ...
- postfix疯狂外发垃圾邮件
分析 一.查找main.cf配置文件 localhost# find / -name main.cf /etc/postfix/main.cf 二.打开/etc/postfix/main.cf来看看. ...
- 转 ogg组件介绍
应用场景:数据分发 ogg的组件: (1) OGG 程序和工具说明 convchk 转换ogg版本的信息 ,该程序可以将checkpoint files 转换成新版本: convprm :OG ...
- CentOS6.5 安装ntopng-1.2.0
0.准备工作 安装libpcap:最好源码安装. yum install -y libpcap* 安装redis yum install -y redis* 1.安装 tar -zxvf ntopng ...