Calculation 2

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1750    Accepted Submission(s): 727

Problem 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*phi[n]/2; 这个好像以前有点印象的。 */ #include<stdio.h> __int64 Euler(__int64 n)
{
__int64 temp=n,i;
for(i=;i*i<=n;i++)
{
if(n%i==)
{
while(n%i==)
n=n/i;
temp=temp/i*(i-);
}
}
if(n!=) temp=temp/n*(n-);
return temp;
} int main()
{
__int64 n,m;
__int64 k;
while(scanf("%I64d",&n)>)
{
if(n==)break;
m=Euler(n);
k=m*n/;
k=n*(n+)/-n-k;
//刚开始,只有k为__in64,错了。
//这里相乘之后,可能会超过int范围。倒置溢出
k=k%;
printf("%I64d\n",k);
}
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. 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. ovs-vsctl 命令详解

    Open vSwitch中有多个命令,分别有不同的作用,大致如下: ovs-vsctl用于控制ovs db ovs-ofctl用于管理OpenFlow switch 的 flow ovs-dpctl用 ...

  2. 740. Delete and Earn

    Given an array nums of integers, you can perform operations on the array. In each operation, you pic ...

  3. 使用git在gitlab上拉取代码的方法

    最近在项目中用到了gitlab,他是一个类似于github的代码托管工具. 因为是第一次使用还不太熟悉,所以在此记录一下. 1.首先需要使用github的注册账号登录gitlab,查看右上角用户头像处 ...

  4. 一,PHP会话机制---cookie

    1,  什么是会话 会话可简单理解为:用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭浏览器,整个过程称之为一个会话. 2,  cookie技术 cookie(小甜饼)是客户端技 ...

  5. Java CAS ABA问题发生的场景分析

    提到了CAS操作存在问题,就是在CAS之前A变成B又变回A,CAS还是能够设置成功的,什么场景下会出现这个问题呢?查了一些资料,发现在下面的两种情况下会出现ABA问题. 1.A最开始的内存地址是X,然 ...

  6. day 17python 面对对象之继承

    一:什么面向对象的继承? 比较官方的说法就是: 继承(英语:inheritance)是面向对象软件技术当中的一个概念.如果一个类别A“继承自”另一个类别B,就把这个A称为“B的子类别”,而把B称为“A ...

  7. 题解 P3628 【[APIO2010]特别行动队 】

    题目大意 ​ 给你一个序列, 将这个序列分成若干段, 每一段的贡献为 \(ax ^ 2 + bx + c\)(x 为 这一段的权值之和) 具体思路 50pts ​ 考虑Dp, 设\(Dp_i\)为前i ...

  8. ApplicationLoader登录失败. Please sign in with an app-specific password.

    打包时登录ApplicationLoader时 报错:Please sign in with an app-specific password. You can create one at apple ...

  9. python 查找字符串中字母的个数

    2017.6.17 更新:好像知道错在哪里了.以第一个为例,输入应该是“AHHaaBBa”,因为直接输入AHHaaBBa时,系统不知到这是一个变量还是字符串,所以必须输入的时候申明定义.既然这样的话, ...

  10. java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification

    ListView UI重绘时触发layoutChildren, 此时会校验listView的mItemCount与其Adapter.getCount是否相同,不同报错. ListView.layout ...