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: ...
随机推荐
- 检测代码潜在bug和质量之SonarQube
参数使用 项目分析参数可以在多个地方设置,继承关系如下: 全局分析参数,通过Web UI设置,作用于所有项目(配置–>通用–>通用中设置) 项目分析参数,通过WebUI设置,覆盖全局参数( ...
- PIE SDK主成分变换
1.算法功能简介 主成分变换(Principal Component Analysis,PCA)又称K-L(Karhunen-Loeve)变换或霍特林(Hotelling)变换,是基于变量之间的相 ...
- python3 + robotframework ride 乱码问题
执行ride时乱码问题 如果被执行的文件所在路径中含有中文,执行时可能会报如下错误 robotframework版本:robotframework-ride 1.7.3.1python 3.7.3 解 ...
- v-on 事件触发
1.v-on 绑定事件 2.methods: 事件绑定语法. 3.v-on:click 可以简写成@click 但是在mvc中会有问题 <!DOCTYPE html> <html&g ...
- error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 "long __cdecl InitD3D(struct HWND__ *)" (?InitD3D
出现如下错误: error LNK2019: 无法解析的外部符号 _Direct3DCreate9@4,该符号在函数 "long __cdecl InitD3D(struct HWND__ ...
- c# MVC5(二) MVC与IOC结合
今天主要来讲解使用Unity来自动注入.Unity前面我们已经详细的介绍过了,如有需要请自行前往去看,今天我们的重点是说MVC与IOC的结合. IOC:控制反转,控制反转的工具是DI(依赖注入:构造函 ...
- 分布式异步框架celery
Celery 1.什么是Clelery Celery是一个简单.灵活且可靠的,处理大量消息的分布式系统 专注于实时处理的异步任务队列 同时也支持任务调度 Celery架构 Celery的架构由三部分组 ...
- 逆向破解之160个CrackMe —— 029
CrackMe —— 029 160 CrackMe 是比较适合新手学习逆向破解的CrackMe的一个集合一共160个待逆向破解的程序 CrackMe:它们都是一些公开给别人尝试破解的小程序,制作 c ...
- vmware-vmx.exe进程应该怎么杀掉
如何解决VMware-vmx.exe无法彻底删除的问题 遇见的问题就是 虚拟机一直黑屏,强制关机之后,无法再次打开的问题. 显示:无法创建新虚拟机: 无法打开配置文件 以独占方式锁定此配置文件失败.另 ...
- 04-C#笔记-数据类型转化
支持强制类型转换. 常用的转化函数如下: 1 ToBoolean如果可能的话,把类型转换为布尔型. 2 ToByte把类型转换为字节类型. 3 ToChar如果可能的话,把类型转换为单个 Unicod ...