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. Macro的写法 `( , ,@ )

    另外的注意点: 1.  同名符号的 “变量捕捉” (varible capture) 解决方式:  with-gensym 生成几个unique name-s, 然后将它们各自绑定上参数值 2. 多次 ...

  2. linux系统shell基础知识入门二

    条件判断语句 test或[],这两是等价的.但用[]这种可能看起来更简洁 必须在[符号和检查条件之间留出空格,而test命令之后也总是应该有一个空格 如果要把test 和then 放一行上,那么必须在 ...

  3. 在verilog中使用格雷码

    格雷码的一些知识: https://baike.baidu.com/item/%E6%A0%BC%E9%9B%B7%E7%A0%81/6510858?fr=aladdin 绿色框起来的是0--15的格 ...

  4. android studio学习----通过github的URL怎么导入新的工程

    这一切的前提是你装了git,有了github帐号,之后就很简单,但是导入之后交给android studio 也会发生各种编译错误,这个时候就需要自己去一一解决了,主要还是  引用依赖版本的问题 第一 ...

  5. CPU和Memory压力测试方法

    一:用原生Centos自带的工具 1. CPU 下面命令会创建 CPU 负荷,方法是通过压缩随机数据并将结果发送到 /dev/null: cat /dev/urandom | gzip -9 > ...

  6. django迁移脚本

    执行migrate报错的解决办法: 想知道migrate为什么报错,需要先了解migrate到底做了什么事情 migrate做了什么事情? 1.将相关的迁移脚本翻译成sql语句,然后在数据库中执行 2 ...

  7. 部署ceph存储集群及块设备测试

    集群环境 配置基础环境 添加ceph.repo wget -O /etc/yum.repos.d/ceph.repo https://raw.githubusercontent.com/aishang ...

  8. MySQL小测试(2)

    2.创建一个stu表,字段有:自增主键id,不为空姓名,默认值性别(枚举类型),无限制身高 create table stu( id int primary key auto_increment, n ...

  9. sudo:有效用户 ID 不是 0,sudo 属于 root 并设置了 setuid 位吗?

    由于误操作导致无法使用sudo切换root用户 直接进入root用户并恢复文件权限,解决办法: chmod 4755 /usr/bin/sudo chmod  755 /usr/libexec/ses ...

  10. 24-C#笔记-异常处理

    # 1 语法 try catch finally(相当于catch(...)) using System; ... public void division(int num1, int num2) { ...