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. [Canvas]Bowman

    试玩请点此下载并用浏览器打开index.html 这个游戏是弓箭射击敌人,用方向键移动人物,空格键发射箭枝. 图例: 代码: <!DOCTYPE html> <html lang=& ...

  2. arcgismanager登陆信息不对

    arcgis版本:arcgis10 安装arcgis server后(java版的win764位系统),发现arcgis管理器登陆界面(http://localhost:8099/arcgismana ...

  3. Android Studio 插件(plugins)或者intellij idea 插件(plugins)无法安装

    通常这种情况出现都因为idea.properties修改了 idea.system.path=${指定路径}/system idea.plugins.path=${idea.config.path}/ ...

  4. [docker]macvlan实现双vlan互通

    关于vlan的冷知识 vlan范围:0~4095 0,4095 保留 仅限系统使用 用户不能查看和使用这些VLAN 1 正常 Cisco默认VLAN 用户能够使用该VLAN,但不能删除它 2-1001 ...

  5. 物联网架构成长之路(23)-Docker练习之Elasticsearch服务搭建

    0. 前言 最近基本都是学一些环境配置,和一些中间件的安装与配置.没有实际编写代码.可能看起来有点水,我对自己的学习方式是,先要了解各个中间件的安装配置以及简单使用,理论应用场景,然后我在小项目中,逐 ...

  6. 简单的topK问题

    /************************************************************************/ /* 求一组数据中的top(K)问题,这是一个经典 ...

  7. 基音检测算法的性能:Performance Evaluation of Pitch Detection Algorithms

    http://access.feld.cvut.cz/view.php?cisloclanku=2009060001 Vydáno dne 02. 06. 2009 (15123 přečtení) ...

  8. Java知多少(103)网络编程之IP地址和InetAddress类

    Java语言的优势之一是Java程序能访问网络资源.Java提供一系列的类支持Java程序访问网络资源. TCP/IP协议和IP地址 为了进行网络通信,通信双方必须遵守通信协议.目前最广泛使用的是TC ...

  9. greendao引起的NoClassDefFoundError异常解决

    在使用Android studio导入eclipse工程师报错,因为原工程引用了greendao的第三方工程包 java.lang.NoClassDefFoundError: org.greenrob ...

  10. (原)android系统下绑定Server的时候报MainActivity has leaked ServiceConnection的错误

    今天在android系统下根据官方的demo代码,我们需要启动一个服务,并绑定,但在程序启动以后,老是报错:   Activity MainActivity has leaked ServiceCon ...