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,对 ...
随机推荐
- css 7.30
1.外提到内联元素,我们会想到有个display的属性是display:inline;这个属性能够修复著名的IE双倍浮动边界(float时margin)问题 2.一般来说,可以为所有块级元素应用 te ...
- 1. Hyper上的CentOS 6.5 网络配置
在hyper上安装了一个centos系统, 默认安装的是命令行模式,网络默认是不开启的.由于是在虚拟机上安装的centos所以需要现在hyper上新添加一个网络适配器后然后再进行下面的设置: 登陆到r ...
- android 学习之RecyclerView
RecyclerView:ListView的升级版,它提供了更好的性能而且更容易使用.该控件是一个可以装载大量的视图集合,并且可以非常效率的进行回收和滚动.当你list中的元素经常动态改变时可以使用R ...
- 转:WebDriver(Selenium2) 判断页面是否刷新的方法
public static boolean waitPageRefresh(WebElement trigger) { int refreshTime = 0; boolean isRefresh = ...
- HDU 2609 How many
最小表示法+Map或者字典树,最小表示法找了个模板,还没学习呢... #include<cstdio> #include<cstring> #include<cmath& ...
- 删除正在登录的SQL账号
exec sp_who '用户名' kill @spid sp_droplogin 用户名
- php获取Linux网卡信息
$data = exec("/sbin/ifconfig"); var_dump($data); 注意:有时候这种方式获取不到,应该是权限问题 在/var/rootP文件中添加ro ...
- 制作windows镜像
下载包含windows驱动的iso: http://222.186.58.77/virtio-win-0.1-30.iso?fid=kF46uzxlPMrgvLDErP0ohhZYwAUASLoCAA ...
- Chapter 1 First Sight——4
Charlie gave me an awkward, one-armed hug when I stumbled my way off the plane. 当我让我蹒跚的从飞机上下来,查理斯单手给 ...
- 基于M9K块配置ROM的LCD12864图片显示实验
先上传三张图片在说 由于串口传输速度较慢,故此实验是在“LCD12864 液晶显示-汉字及自定义显示(并口)”基础上进一步修改而来.在写代码之前 ...