Description

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.

Input

For 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.

Output

For 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)/2-n*Euler(n)/2。
AC代码:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <set>
using namespace std;
typedef long long LL;
const int maxn = 1e6+;
const LL mod = ;
LL n;
LL get_Euler(LL x){
LL res = x; ///初始值
for(LL i = 2LL; i * i <= x; ++i) {
if(x % i == ) {
res = res / i * (i - ); ///先除后乘,避免数据过大
while(x % i == ) x /= i;
}
}
if(x > 1LL) res = res / x * (x - ); ///若x大于1,则剩下的x必为素因子
return res;
} int main(){
while(cin >> n && n) {
cout << (n * (n - ) / - n * get_Euler(n) / ) % mod << endl;
}
return ;
}
 

题解报告:hdu 3501 Calculation 2 (欧拉函数的扩展)的更多相关文章

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

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

  2. hdu 3501 容斥原理或欧拉函数

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

  3. 题解报告:hdu 2588 GCD(欧拉函数)

    Description The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written ...

  4. HDU3501 Calculation 2 [欧拉函数]

    题目传送门 Calculation 2 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. HDU 5430 Reflect(欧拉函数)

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5430 从镜面材质的圆上一点发出一道光线反射NNN次后首次回到起点. 问本质不同的发射的方案数. 输入描述 ...

  6. hdu 5279 Reflect phi 欧拉函数

    Reflect Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/contest_chi ...

  7. HDU 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. HDU 1695 GCD(欧拉函数+容斥原理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...

  9. HDU 2588 GCD(欧拉函数)

    GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  10. HDU 1787 GCD Again(欧拉函数,水题)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. ACM组队安排-——杭电校赛(递推)

    #include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #in ...

  2. Network -UVa315(连通图求割点)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=sh ...

  3. poj——1422 Air Raid

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8577   Accepted: 5127 Descript ...

  4. Linux MariaDB 遗忘密码后重置密码

    Linux MariaDB 遗忘密码后重置密码 MariaDB 是 MySQL 的一个分支数据库.处理的办法和 MySQL 相同. 修改 MySQL 配置文件 在 [mysqld] 追加配置项: [r ...

  5. Python学习系列之文件操作

    Pyhton文件打开方式 with= open('文件路径','打开模式') as f:#PS:python3提供了with语句来帮我们自动调用close方法,所以说无论打开文件是否出错都能自动正确的 ...

  6. golang time.Duration()的问题解疑

    原文:  How to multiply duration by integer? 看到golang项目中的一段代码, ---------------------------------------- ...

  7. iOS下JSON反序列化开源库

    iOS下JSON字符串反序列化成对象.在正式的项目中比較常见.例如以下几个经常使用开源库.能够依据个人喜好任选其一: 1. JSONModel: https://github.com/icanzilb ...

  8. Android oat文件提取转换

    说明: 1.手机厂商可以修改Android源码并进行编译后再生成oat格式文件在手机上存储,比如boot-okhttp.oat,boot-framework.oat. 2.自带的apk可以调用这些模块 ...

  9. java 和 Android Base64加密

    Java8 Base64 Java 8 新特性 在Java 8中,Base64编码已经成为Java类库的标准. Java 8 内置了 Base64 编码的编码器和解码器. Base64工具类提供了一套 ...

  10. 关于hive

    这两天在研究了hbase,hadoop,hive,spark 由于spark.py不支持clust(jar才支持,但是太麻烦了>_<) 所以最终决定使用hive 在hive中用create ...