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

用个互斥原理就可以了

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
//#define cl clear()
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
using namespace std;
vector< int >v;
const double pi=acos(-1.0);
ll cal(ll x,ll n)
{
if(x==n) return 0;
int a=(n-1)/x;
return (x*a+(x*a*(a-1))/2)%mod;
}
ll solve(ll n)
{
ll x=n;
for(int i=2;i*i<=x;i++)
{
// cout<<"1"<<endl;
if(x%i==0)
{
v.pb(i);
while(x%i==0)
{
x/=i;
}
}
}
if(x>1) v.pb(x);
ll sum=0;
for(int i=1;i<(1<<v.size()) ;i++)
{
ll bits=0,ans=1;
for(int j=0;j<v.size() ;j++)
{
if((1<<j)&i)
{
bits++;
ans*=v[j];
}
}
if(bits&1)
sum=(sum+cal(ans,n))%mod;
else
{
sum=(sum-cal(ans,n));
while(sum<0)
sum+=mod;
}
}
return sum;
}
int main()
{
// freopen("output1.txt", "r", stdin);
ll n;
while(1)
{
v.clear();
sf("%I64d",&n);
if(n==0) return 0;
pf("%I64d\n",solve(n));
}
}

B - 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. HTML5新特性[ Notifications ] 桌面消息

    在执行完以上代码后,我们就成功地创建了一个消息框实例,在Chrome下面它最终会显示成这样: 到这里我们已经成功了一半,但能不能正确地显示出这个消息框,最终还取决于用户的授权.鉴于浏览器的安全机制,只 ...

  2. Java 8 新特性——Lambdas 表达式

    本文内容 引入 测试数据 collect(toList()) map filter flatMap max 和 min reduce 整合操作 参考资料 Java 8 对核心类库的改进主要包括集合类的 ...

  3. 微软BI 之SSIS 系列 - 带有 Header 和 Trailer 的不规则的平面文件输出处理技巧

    案例背景与需求介绍 之前做过一个美国的医疗保险的项目,保险提供商有大量的文件需要发送给比如像银行,医疗协会,第三方服务商等.比如像与银行交互的 ACH 文件,传送给协会的 ACH Credit 等文件 ...

  4. JS 判断object是否包含某个键

    1. myObj.hasOwnProperty('myKey'); 2. if ('key' in myObj)

  5. apache的性能调配 MaxClients 与MaxRequestsPerChild

    因近期服务不稳定,现象和这个比较类似http://hi.baidu.com/xinfeng999/blog/item/1aea470e214ab1cd7acbe1ed.html根据现象来对APACHE ...

  6. appium 获取android 粘贴板上的内容

    appium 新版本增加了获取粘贴板的内容.如果使用appium旧版本,获取粘贴板的内容不是那么容易的,甚至百度谷歌各种搜,都无法找到合适的解决方法.新版本获取android 粘贴板内容就显得很容易了 ...

  7. Linux好用的工具命令 - nl/du

    nl 添加行号后打印输出文本内容,以下例子演示了cat 和nl 输出nlDemo文档的区别. [root@ptarmiganantelope:~]# cat nlDemo root:x:0:0:roo ...

  8. 基于Docker的redis集群搭建

    Redis集群官方介绍:http://www.redis.cn/topics/cluster-tutorial.html 基于Docker搭建Redis集群 环境:6个节点,三主三从 制作Redis镜 ...

  9. 点云PCL中小细节

    计算点与点之间的距离的平局距离 double computeCloudResolution (const pcl::PointCloud<PointType>::ConstPtr & ...

  10. Java 继承中构造方法的执行顺序问题

    在Java中,如果一个类没有任何显式创建的构造器则该类默认会有一个无参构造器:如果显式创建了有参构造器则该类就不再有默认无参构造器. 在Java继承中,构造器并不能被继承,而是被显示或隐式调用. 1. ...