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: ...
随机推荐
- i春秋——“百度杯”CTF比赛 九月场——123(Apache解析pht,phtml,php3,phps等 php别名)
网页源码提示用户信息在user.php中,直接访问是不会有显示的,于是查找相应的备份文件,vim交换文件等,最后发现/user.php.bak 用burp采用如下配置开始爆破 最后爆破出两个账号 登录 ...
- SAP常见查询组合
做SAP开发的,SELECT是必不可少的.新语法出了不少'新鲜'的语法,用法也是五花八门. 新语法有新语法的好处,老语法有老语法的优势. 新语法里把很多的逻辑处理,分组,排重,内表处理全都放到一些关键 ...
- JVM参数最佳实践:元空间的初始大小和最大大小
本文阅读时间大约4分钟. JVM加载类的时候,需要记录类的元数据,这些数据会保存在一个单独的内存区域内,在Java 7里,这个空间被称为永久代(Permgen),在Java 8里,使用元空间(Meta ...
- pip requirements.txt
生成文件 pip freeze > requirements.txt 依赖库会导到于requirements.txt 比如: image.png 从requirements.txt安装依赖库 ...
- Mac Brew 安装及配置
mac 终端下,执行以下命令,即可安装brew: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homeb ...
- Linux shell awk数组使用
awk中使用数组 一.数组格式 数组是一个包含一系列元素的表. 格式如下: abc[1]="xiaohong" abc[2]="xiaolan" ...
- Chrome无界面启动使用
Method1: from selenium import webdriver # 创建chrome参数对象opt = webdriver.ChromeOptions() # 把chrome设置成无界 ...
- ansible自动化运维03
ansible自动化运维常用模块 常用模块实现的功能:安装软件包:修改配置文件:创建程序用户组:创建目录,并修改所属和权限:挂载:启动服务:测试. command模块: shell模块: 注意:com ...
- Alipay 支付类
本版本参考网友 <?php namespace App\Tools; class Alipay { //应用ID,您的APPID. private $appID = '111'; //商户私钥 ...
- 混合高斯模型(Gaussian mixture model, GMM)
1. 前言 这就是为什么我要学习一下二维高斯分布的原因: 总感觉数学知识不够用呐,顺带把混合高斯模型也回顾一下. 2. 单高斯模型(Gaussian single model, GSM) 2.1 一维 ...