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.

InputFor 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.OutputFor each test case, you should print the sum module 1000000007 in a line.Sample Input

3
4
0

Sample Output

0
2 如果gcd(n,i)==1,gcd(n,n-i)==1
证:i=1(mod n)
  -i=-1(mod n)
  n-i=-1+n (mod n)
  n-i=1 (mod n)
通过欧拉函数一个数n中存在phi(n)个与之互质的数,因为i+(n-i)为n也就是有n对。
则与n互质数目之和为res=phi(n)/2*n,
ans=(n-1)*n/2-res。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define N 1000010
#define maxn 1000010
#define mod 1000000007
using namespace std;
typedef long long ll;
int p[N];
int prime[N];
int pn=0;
bool vis[N];
int main()
{
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
prime[pn++] = i;
for (int j = i; j < N; j += i)
vis[j] = 1;
}
ll n;
while(~scanf("%lld",&n),n)
{
ll r=n;
ll phi=n;
for(int i=0;prime[i]*prime[i]<=r;i++)
{
ll tem=0;
while(r%prime[i]==0)
{
r/=prime[i];
tem++;
}
if(tem)
phi=phi-phi/prime[i];
}
if(r!=1)
phi-=phi/r;
ll rem=n*phi/2;
ll ans=n*(n-1)/2;
printf("%lld\n",(ans-rem)%mod);
}
}

  

hdu_3501_Calculation 2的更多相关文章

随机推荐

  1. selinux下修改sshd端口号

    21 如果已开selinux,修改sshd配置文件  # vim /etc/ssh/sshd_config中的端口号后 重启SSH服务  # systemctl restart sshd.servic ...

  2. Nginx + Keepalived 实例(测试可行)

    Nginx_Master: 192.168.1.103 提供负载均衡 Nginx_BackUp: 192.168.1.104 负载均衡备机 Nginx_VIP_TP: 192.168.1.108 网站 ...

  3. 关于docker remote api未授权访问漏洞的学习与研究

    漏洞介绍: 该未授权访问漏洞是因为docker remote api可以执行docker命令,从官方文档可以看出,该接口是目的是取代docker 命令界面,通过url操作docker. docker ...

  4. jQuery Validate验证框架详解(转)

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...

  5. 创建Graphics对象与Pen对象

    Graphics对象表示GDI+绘图表面,是用于创建图形图像的对象,所以要通过GDI+创建绘图,必须先创建Graphics对象,然后才可以使用GDI+的笔.刷等结合颜色.字体等对象进行绘制线条形状.填 ...

  6. npm 包下载很慢的解决办法

    原因: 国内访问外网都很慢,甚至不能访问!安装Node时自带的npm地址默认是:http://registry.npmjs.org  三种方法: 1.通过config命令 npm config set ...

  7. Active Directory 域服务对象

    局域网计算机控制中心 可以在DC上控制所有局域网资源(计算机 .用户.设备) 大中型企业管理必备. 最后,它还可以让开发人员集成LDAP身份认证,使用域账号登录应用. 也就是说,此企业的所有系统,都可 ...

  8. Java编译及装载

    Java类加载机制 JVM将类加载过程划分为三个步骤:装载.链接和初始化. 装载(Load):装载过程负责找到二进制字节码并加载至JVM中,JVM通过类的全限定名(com.bluedavy. Hell ...

  9. spring笔记4-事务管理

    一.xml配置文件形式 通过转账案例,学习事务管理 1.建立数据库 2.编写entity package huguangqin.com.cnblogs.entity; public class Use ...

  10. Cg shadow of sphere

    参考自:https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Soft_Shadows_of_Spheres using UnityEngine; ...