【题目分析】

卷积太有趣了。

最终得出结论,互质数和为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积的更多相关文章

  1. HDU 3501 Calculation 2(欧拉函数)

    Calculation 2 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. HDU 3501 Calculation 2------欧拉函数变形

    Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 3501 Calculation 2 (欧拉函数)

    题目链接 题意 : 求小于n的数中与n不互质的所有数字之和. 思路 : 欧拉函数求的是小于等于n的数中与n互质的数个数,这个题的话,先把所有的数字之和求出来,再减掉欧拉函数中所有质数之和(即为eula ...

  4. hdu 3501 Calculation 2 (欧拉函数)

    题目 题意:求小于n并且 和n不互质的数的总和. 思路:求小于n并且与n互质的数的和为:n*phi[n]/2 . 若a和n互质,n-a必定也和n互质(a<n).也就是说num必定为偶数.其中互质 ...

  5. HDU 3501 Calculation 2

    题目大意:求小于n的与n不互质的数的和. 题解:首先欧拉函数可以求出小于n的与n互质的数的个数,然后我们可以发现这样一个性质,当x与n互质时,n-x与n互质,那么所有小于n与n互质的数总是可以两两配对 ...

  6. 题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)

    Description Given a positive integer N, your task is to calculate the sum of the positive integers l ...

  7. BZOJ 1101 [POI2007]Zap ——Dirichlet积

    [题目分析] Dirichlet积+莫比乌斯函数. 对于莫比乌斯函数直接筛出处理前缀和. 对于后面向下取整的部分,可以分成sqrt(n)+sqrt(m)部分分别计算 学习了一下线性筛法. 积性函数可以 ...

  8. HDU——T 3501 Calculation 2

    http://acm.hdu.edu.cn/showproblem.php?pid=3501 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  9. Calculation 2 HDU - 3501

    https://vjudge.net/problem/HDU-3501 不会做啊...记一下做法 做法是计算小于n且与n互质的数的和:根据如果gcd(i,n)==1,那么gcd(n-i,n)==1,对 ...

随机推荐

  1. hdu1285 确定比赛名次(拓扑排序)

    确定比赛名次 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  2. java 子类继承父类成员变量的隐藏、实现方法的重写

    成员变量的隐藏和方法的重写 Goods.java public class Goods { public double weight; public void oldSetWeight(double ...

  3. android 5.1 API简介

    android 5.1介绍: http://developer.android.com/about/versions/android-5.1.html?utm_campaign=lollipop-51 ...

  4. Adobe Acrobat 9 Pro 注册码

    来自百度知道,记录与此,以备后用http://zhidao.baidu.com/question/177914535.html 如果你的系统盘是C盘,那么就删除:c:/Documents and Se ...

  5. Nginx配置-伪静态,隐藏index.php大入口

    server { listen ; server_name ; root E:/www/wvtuan/; index index.php index.html; log_not_found off; ...

  6. idx_rebuild_diff_idx_l.sql

    1. set echo on feedback on set timing on set time on set pagesize 1000 set linesize 150 spool 02_do_ ...

  7. 【学生成绩管理系统】 大二c语言作业

    几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...

  8. 智力大冲浪(riddle)

    智力大冲浪(riddle) 题目描述 小伟报名参加中央电视台的智力大冲浪节目.本次挑战赛吸引了众多参赛者,主持人为了表彰大家的勇气,先奖励每个参赛者m元.先不要太高兴!因为这些钱还不一定都是你的?!接 ...

  9. jaxb异常 Class has two properties of the same name username

    import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; im ...

  10. MySQL中文乱码修改

    一.从服务端进行修改 show variables like "%char%"; 然后可能显示如下信息,注意红色部分,不同的用户可能实际情况不同,但是需要保证除了 filesyst ...