Calculation 2

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

方法:\

\(ans=\frac{n*(n-1)}{2}-\frac{n\phi(n)}{2}\)\

证明:\

\(1.\)总情况为\(\frac{n*(n-1)}{2}\)\

\(2.\)不合法为\(\frac{n\phi(n)}{2}\)\

结论\(1:\)若\((a,n)=1,\)则\((n-a,n)=1\)

证明:

\((a,n)=(n-a,a)=(n-a,n)\)(更相减损法)

结论\(2:\)不合法和为\(\frac{n\phi(n)}{2}\)

\(\ \ \ \ \ \ 1.\phi(n) \% 2=0\)

不合法的数列\(a_1,a_2,a_3...(n-a_{\phi(n)-2})-(n-a_{\phi(n)-1})-(n-a_{\phi(n)})\)

\(\sum_{i=1}^na_i=\frac{n\phi(n)}{2}\)



\(\ \ \ \ \ \ 2.\phi(n) \% 2=1\)

不合法的数列\(a_1,a_2,a_3...\frac{n}{2}...(n-a_{\phi(n)-2})-(n-a_{\phi(n)-1})-(n-a_{\phi(n)})\)

\(\sum_{i=1}^na_i=\frac{n\phi(n)}{2}\)

综上\(:\)不合法为\(\frac{n\phi(n)}{2}\)

\(\mathfrak{Talk\ is\ cheap,show\ you\ the\ code.}\)

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
# define Type template<typename T>
# define read read1<int>()
Type inline T read1()
{
T t=0;
bool ty=0;
char k;
do k=getchar(),(k=='-')&&(ty=1);while('0'>k||k>'9');
do t=(t<<3)+(t<<1)+(k^'0'),k=getchar();while('0'<=k&&k<='9');
return ty?-t:t;
}
# define int long long
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
int work(int n)
{
int tn=n;
for(int i=2;i*i<=n;++i)
if(!(n%i))
{
while(!(n%i))n/=i;
tn=tn/i*(i-1);
}
if(n!=1)tn=tn/n*(n-1);
return tn;
}
signed main()
{
for(int n;n=read;)
printf("%lld\n",(n*(n-1)-n*work(n))/2ll%1000000007ll);
return 0;
}

Calculation 2的更多相关文章

  1. OpenCASCADE Curve Length Calculation

    OpenCASCADE Curve Length Calculation eryar@163.com Abstract. The natural parametric equations of a c ...

  2. hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律

    http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...

  3. inconsistent line count calculation in projection snapshot

    1.现象 在vs2013中,按Ctrl + E + D格式化.cshtml代码,vs2013系统崩溃.报:inconsistent line count calculation in projecti ...

  4. 贪心 HDOJ 4726 Kia's Calculation

    题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...

  5. Calculation

    定义一个Strategy接口,其中定义一个方法,用于计算 using System; using System.Collections.Generic; using System.Linq; usin ...

  6. WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results

    GLES2.0: Some device will give a warning on compling shaders(yet the compling will succeed), and the ...

  7. VKP5 Price Calculation – List Variant & KZPBL (Delete site level)

    List Variant: Configuration in Logistic General –> Retail Pricing –> Sales Price Calculation – ...

  8. hdu 2837 Calculation 指数循环节套路题

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

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

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

  10. Calculation(dfs+状压dp)

    Problem 1608 - Calculation Time Limit: 500MS   Memory Limit: 65536KB    Total Submit: 311  Accepted: ...

随机推荐

  1. 深入挖崛:mysql主从复制原理

    一.基本原理 MySQL复制过程分成三步: 1).master将改变记录到二进制日志(binary log).这些记录过程叫做二进制日志事件,binary log events: 2).slave将m ...

  2. Mybatis映射文件中的标签的使用

    <foreach> <!-- foreach --> <delete id="delMulti" parameterType="java.u ...

  3. centos7放行1521端口

    [root@localhost ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent success [root@localho ...

  4. Nginx 高级配置-实现多域名HTTPS

    Nginx 高级配置-实现多域名HTTPS 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx支持基于单个IP实现多域名的功能 Nginx支持基于单个IP实现多域名的功能 ...

  5. 【Servlet】The servlets named [ByteServlet] and [content.ByteServlet] are both mapped to the url-pattern [ByteServlet] which is not permitted

    创建时间:6.30 The servlets named [ByteServlet] and [content.ByteServlet] are both mapped to the url-patt ...

  6. 团队项目-Beta冲刺及发布说明

    请大家在每次作业开头添加格式描述: 这个作业属于哪个课程 <课程的链接> 这个作业要求在哪里 <作业要求的链接> 团队名称 <写上团队名称>(附上团队博客链接) 这 ...

  7. 一天撸完《 Learning Jupyter 5 2nd Edition》

    因为工作需要了解这个应用的大概功能. 网上找不到下载的,CSDN没积分. 最后,在道客上找到了这个PDF.花了一天时间浏览了一下, 只留意了python功能,其它语言略去. widget和jupyte ...

  8. JS 中的 new 操作符

    按照javascript语言精粹中所说,如果在一个函数前面带上new来调用该函数,那么将创建一个隐藏连接到该函数的prototype成员的新对象,同时this将被绑定到那个新对象上.这个话很抽象,我想 ...

  9. C# XML封装

    /************************************************* * 描述: * * Author:yuanshuo@healthcare.cn * Date:20 ...

  10. 【Excel】IF函数

    判断条件: 一版判断:1>2大于   1<2小于   1=2等于   1<>2不等于  1>=2 1<=2 交集:AND() 并集:OR() 多条件:以后补