Calculation 2
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
0Sample 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的更多相关文章
- OpenCASCADE Curve Length Calculation
OpenCASCADE Curve Length Calculation eryar@163.com Abstract. The natural parametric equations of a c ...
- hdu4965 Fast Matrix Calculation (矩阵快速幂 结合律
http://acm.hdu.edu.cn/showproblem.php?pid=4965 2014 Multi-University Training Contest 9 1006 Fast Ma ...
- inconsistent line count calculation in projection snapshot
1.现象 在vs2013中,按Ctrl + E + D格式化.cshtml代码,vs2013系统崩溃.报:inconsistent line count calculation in projecti ...
- 贪心 HDOJ 4726 Kia's Calculation
题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...
- Calculation
定义一个Strategy接口,其中定义一个方法,用于计算 using System; using System.Collections.Generic; using System.Linq; usin ...
- 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 ...
- VKP5 Price Calculation – List Variant & KZPBL (Delete site level)
List Variant: Configuration in Logistic General –> Retail Pricing –> Sales Price Calculation – ...
- hdu 2837 Calculation 指数循环节套路题
Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 3501 Calculation 2(欧拉函数)
Calculation 2 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- Calculation(dfs+状压dp)
Problem 1608 - Calculation Time Limit: 500MS Memory Limit: 65536KB Total Submit: 311 Accepted: ...
随机推荐
- 微服务架构 ------ Ubuntu下Docker的安装
1.准备一个全新的Ubuntu环境 2.准备安装Docker及其依赖 apt-get update 更新数据源 apt-get -y install apt-transport-https ca-ce ...
- Spring所有注解大揭秘
声明bean的注解 @Component 组件,没有明确的角色 @Service 在业务逻辑层使用(service层) @Repository 在数据访问层使用(dao层) @Controller 在 ...
- day 69作业
""" 1.按照上方 知识点总结 模块,总结今天所学知识点: 2.有以下广告数据(实际数据命名可以略做调整) ad_data = { tv: [ {img: 'img/t ...
- org.json package
JSON is a light-weight,language independent,data interchange format. org.json package implement JSON ...
- 让天堂的归天堂,让尘土的归尘土——谈Linux的总线、设备、驱动模型
本文系转载,著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 作者: 宋宝华 来源: 微信公众号linux阅码场(id: linuxdev) 公元1951年5月15日的国会听证上, ...
- windows定期删除文件
:: 定时清理客户端上传导入包文件 @echo off title 清理客户端上传导入包文件 :: 导入包文件目录 set log_dir="F:\http\uploadzip\web\ht ...
- php静态化介绍
1.动态URL地址设置成静态形式http://state.com/index.php?c=play&a=index&id=16267 ------>http://state.co ...
- HDU 1548 A strange lift 题解
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- load address、entry point、 bootm address以及kernel运行地址
load address:加载地址 load_addr mkimage -a entry point: 入口地址 entry_point mkimage -e bootm ...
- gradle应用
官网下载 http://services.gradle.org/distributions/ 解压并配置环境 1.解压gradle到你想要的目录 2.配置环境变量 GRADLE_HOME=D:\gra ...