Calculation 2

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

Submit Status

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互质的数的和模1000000007的值。
 
解题思路:
欧拉函数,先求出小于n且与n互质的数的和,用总数减去互质的数的和,就得到了不互质的数的和。
 
代码:
 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=;
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n)
{
long long temp=n,eular=;
long long ans=(temp*(temp+)/)%mod;
for(int i=;i*i<=temp;i++)
if(temp%i==)
{
temp/=i;
eular*=i-;
while(temp%i==)
{
temp/=i;
eular*=i;
}
}
if(temp>) eular*=temp-;
eular%=mod;
temp=n;
long long w=(eular*temp/)%mod;
ans-=w;
ans-=n;
while(ans<) ans+=mod;
printf("%lld\n",ans);
}
return ;
}

Calculation 2

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. HDU3501 Calculation 2 [欧拉函数]

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

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

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

  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(欧拉函数+容斥原理)

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

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

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

  9. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  10. hdu 2814 快速求欧拉函数

    /** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...

随机推荐

  1. AsEnumrable和AsQueryable的区别

    http://www.cnblogs.com/jianglan/archive/2011/08/11/2135023.html 在写LINQ语句的时候,往往会看到.AsEnumerable() 和 . ...

  2. form 练习

    <form>姓:<input type="text" name="firstname" /><br />名:<inpu ...

  3. Centos下配置Java运行环境

    今天搞了个阿里云,Centos主机 先搞了Tomcat 然后配置Java环境 1.修改文件可执行 chmod 777 (u+x) 文件名 2.配置环境变量 vi /etc/profile 加入如下代码 ...

  4. Qt带进度条的启动界面(继承QSplashScreen,然后使用定时器)

    通过继承QSplashScreen类,得到CMySplashScreen类,然后在CMySplashScreen中定义QProgressBar变量,该变量以CMySplashScreen为父类,这样就 ...

  5. 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅶ(延伸:堆排序的实现)

    2.4.5 堆排序 我们可以把任意优先队列变成一种排序方法.将所有元素插入一个查找最小元素的有限队列,然后再重复调用删除最小元素的操作来将他们按顺序删去.用无序数组实现的优先队列这么做相当于进行一次插 ...

  6. FlexComboBoxTree

    在我的CSDN资源中有项目工程文件.下载导入工程即可看到效果,下面是地址. http://download.csdn.net/detail/cym_lmy/6326053 MyCombBoxTree1 ...

  7. Java应用开发的一条经验

    一旦为应用建立良好的基础设施, 后续的开发就会变得容易而快速.  这些基础设施包括: 1.   线程池的建立.配置: 在 JDK 并发库的基础上建立更适合于应用的并发使用接口: 2.   跨多数据源的 ...

  8. 制作nginx的rpm包出现问题

    在学习打包rpm,找到了个不错的参考站点  https://src.fedoraproject.org/cgit/rpms/ 过程: git clone -b el6 git://pkgs.fedor ...

  9. Bin & Jing in wonderland(概率,组合数学)

    Problem 2103 Bin & Jing in wonderland Accept: 201    Submit: 1048 Time Limit: 1000 mSec    Memor ...

  10. DreamWeaver文件保存时,提示"发生共享违例"问题的解决方法

    在学习牛腩老师的JS视频中,视频中的例子要求实现一个是23个3相乘的结果,在用Dreamweaver制作时,, <script language="javascript" t ...