Given a positive integer N, your task is to calculate the sum of the positive integers less than N which are not coprime to N. A is said to be coprime to B if A, B share no common positive divisors except 1.

InputFor each test case, there is a line containing a positive integer N(1 ≤ N ≤ 1000000000). A line containing a single 0 follows the last test case.OutputFor each test case, you should print the sum module 1000000007 in a line.Sample Input

3
4
0

Sample Output

0
2

给定一个正整数N,你的任务是计算小于N的正整数的和,这些正整数不是共圆到N的。

输入

对于每个测试用例,有一行包含一个正整数N(1≤N≤1000000000)。最后一个测试用例后面有一行包含一个0。

输出

对于每个测试用例,您应该在一行中打印sum模块1000000007。

样例输入

3.

4

0

样例输出

0

2

思路:本来以为这道题会是欧拉函数只不过返回的不是欧拉数,而是GCD(n,i)大于一的和,结果WA了

想了想,以6为例

1 2 3 4 5 6 其中 2 3 4 都是满足题意的,但是欧拉函数不会走4,他只会走它所有的质因子

没有办法,只有看大佬题解,借鉴后看到了 求互质的数字和可以直接利用 n * enler( n) / 2求解,而此题要求的是非互质的,同样可以使用这个性质

于是就一个欧拉函数,轻松AK,看到大佬用容斥写,哎还是见识太短,学的太少,小菜鸟今天又是队伍倒一。。。。。。。。

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#define Mod 1000000007
using namespace std;
typedef long long ll;
const ll N = +;
int elh[N];
int a;
ll Euler(ll n)
{
ll res =n;
for(int i=;i<=n/i;i++)
{
if(n%i==)
{
res = res-res/i;
}
while(n%i==)n/=i;
}
if(n>)res =res- res/n;
return res%Mod;
}
int main()
{
while(~scanf("%lld",&a)&&a)
{
cout <<(a*(a--Euler(a))/)%Mod<<endl;
}
return ;
}

C - Calculation 2 HDU - 3501 (欧拉)的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. 欧拉函数 || Calculation 2 || HDU 3501

    题面: 题解:欧拉函数的基础应用,再套个很 easy 的等差数列前 n 项和就成了. 啊,最近在补作业+准备月考+学数论,题就没怎么写,感觉菜得一匹>_< CSL加油加油~! 代码: #i ...

  3. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  4. hdu 2654(欧拉函数)

    Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. The Best Path HDU - 5883 欧拉通路

    图(无向图或有向图)中恰好通过所有边一次且经过所有顶点的的通路成为欧拉通路,图中恰好通过所有边一次且经过所有顶点的回路称为欧拉回路,具有欧拉回路的图称为欧拉图,具有欧拉通路而无欧拉回路的图称为半欧拉图 ...

  8. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  9. hdu 2586 欧拉序+rmq 求lca

    题意:求树上任意两点的距离 先说下欧拉序 对这颗树来说 欧拉序为 ABDBEGBACFHFCA 那欧拉序有啥用 这里先说第一个作用 求lca 对于一个欧拉序列,我们要求的两个点在欧拉序中的第一个位置之 ...

随机推荐

  1. python遍历文件夹中所有文件夹和文件,os.walk

    python中可以用os.walk来遍历某个文件夹中所有文件夹和文件. 例1: import os filePath = 'C:/Users/admin/Desktop/img' for dirpat ...

  2. 【AMAD】django-compressor -- 将JS和CSS文件压缩为一个缓存文件

    简介 个人评分 简介 django-compressor1的example: {% load compress %} {% compress css %} <link rel="sty ...

  3. redis 获取方式和安装(windows)

    Windows redis :https://github.com/MSOpenTech/redis/releases Linux redis :https://github.com/phpredis ...

  4. There are no packages available

    { "bootstrapped": true, "channels": [ "https://raw.githubusercontent.com/Ja ...

  5. [转帖]Linux cpufreq 机制了解

    Linux cpufreq 机制了解 https://www.cnblogs.com/armlinux/archive/2011/11/12/2396780.html 引用文章链接: http://w ...

  6. [转帖]【Oracle】详解Oracle中NLS_LANG变量的使用

    [Oracle]详解Oracle中NLS_LANG变量的使用 https://www.cnblogs.com/HDK2016/p/6880560.html NLS_LANG=LANGUAGE_TERR ...

  7. 小记------phoenix安装搭建

        1.下载与hbase对应版本的phoenix      http://phoenix.apache.org/download.html   2.解压  tar -zxvf apache-pho ...

  8. C++ 简单实现 依赖注入(IOC)

    由于C++ 不支持“反射机制”, 在C++中需要实现依赖注入或控制反转需要增加辅助程序.例如在Windows 开发程序中根据类名动态创建对象,需要在类定义中增加宏.本文主要介绍C++ Ioc的一种实现 ...

  9. 2.4容错保护:Hystrix

    在ribbon使用断路器 改造serice-ribbon 工程的代码,首先在pox.xml文件中加入spring-cloud-starter-hystrix的起步依赖: 引入 <dependen ...

  10. Scrapy爬虫-win7下创建运行项目

    开始的时候,我只安装了python3.5,安装不了scrapy库,网上搜了一下说是scrapy不支持python3.x 然后,我就又安装了python2.7 为了,默认使用2.7,我在环境变量path ...