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.

InputFor 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.OutputFor each test case, you should print the sum module 1000000007 in a line.Sample Input

3
4
0

Sample Output

0
2

给定一个正整数N,你的任务是计算小于N的正整数的和,这些正整数不是共圆到N的。

输入

对于每个测试用例,有一行包含一个正整数N(1≤N≤1000000000)。最后一个测试用例后面有一行包含一个0。

输出

对于每个测试用例,您应该在一行中打印sum模块1000000007。

样例输入

3.

4

0

样例输出

0

2

思路:本来以为这道题会是欧拉函数只不过返回的不是欧拉数,而是GCD(n,i)大于一的和,结果WA了

想了想,以6为例

1 2 3 4 5 6 其中 2 3 4 都是满足题意的,但是欧拉函数不会走4,他只会走它所有的质因子

没有办法,只有看大佬题解,借鉴后看到了 求互质的数字和可以直接利用 n * enler( n) / 2求解,而此题要求的是非互质的,同样可以使用这个性质

于是就一个欧拉函数,轻松AK,看到大佬用容斥写,哎还是见识太短,学的太少,小菜鸟今天又是队伍倒一。。。。。。。。

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#define Mod 1000000007
using namespace std;
typedef long long ll;
const ll N = +;
int elh[N];
int a;
ll Euler(ll n)
{
ll res =n;
for(int i=;i<=n/i;i++)
{
if(n%i==)
{
res = res-res/i;
}
while(n%i==)n/=i;
}
if(n>)res =res- res/n;
return res%Mod;
}
int main()
{
while(~scanf("%lld",&a)&&a)
{
cout <<(a*(a--Euler(a))/)%Mod<<endl;
}
return ;
}

最新文章

  1. BZOJ2599——[IOI2011]Race
  2. java内存分配原理
  3. BZOJ 1835 基站选址(线段树优化DP)
  4. 【阿里云产品公测】在Laravel4框架中使用阿里云OCS缓存
  5. top每个参数的意义
  6. 常见 jar包详解
  7. GridView获取单个单元格的值
  8. oracle 语句
  9. http接口测试浏览器插件
  10. jquery 产品查看放大镜组件
  11. 在游览器上可以连网,Ionic打包后不能连接网络
  12. 【python 字符串】 字符串的相关方法(一)
  13. ASP.NET Core知多少(6):VS Code联调Angular + .NetCore
  14. 打包发布Python模块或程序,安装包
  15. 一键部署office的工具——OTool
  16. 跟我一起用node-express搭建一个小项目(node连接mongodb)[三]
  17. centos7 安装Node.js并配置为全局可用
  18. SWT中ole/activex实践--操作word的一个例子
  19. Web项目添加Maven支持
  20. 关于SQL 行转列的办法

热门文章

  1. jmeter5实现文件上传接口测试
  2. 删除kubernetes-dashboard
  3. 思科S系列220系列交换机多个漏洞预警
  4. C++——文件的读写
  5. 最新 顺网科技java校招面经 (含整理过的面试题大全)
  6. springBoot--组合注解RestController,GetMapping,PostMapping
  7. 第35课.函数对象分析(&quot;()&quot;重载)
  8. [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中
  9. HanLP-基于HMM-Viterbi的人名识别原理介绍
  10. Pandas 读取超过 65536 行的 Excel 文件