C - Calculation 2 HDU - 3501 (欧拉)
2024-09-01 21:43:21
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 ;
}
最新文章
- BZOJ2599——[IOI2011]Race
- java内存分配原理
- BZOJ 1835 基站选址(线段树优化DP)
- 【阿里云产品公测】在Laravel4框架中使用阿里云OCS缓存
- top每个参数的意义
- 常见 jar包详解
- GridView获取单个单元格的值
- oracle 语句
- http接口测试浏览器插件
- jquery 产品查看放大镜组件
- 在游览器上可以连网,Ionic打包后不能连接网络
- 【python 字符串】 字符串的相关方法(一)
- ASP.NET Core知多少(6):VS Code联调Angular + .NetCore
- 打包发布Python模块或程序,安装包
- 一键部署office的工具——OTool
- 跟我一起用node-express搭建一个小项目(node连接mongodb)[三]
- centos7 安装Node.js并配置为全局可用
- SWT中ole/activex实践--操作word的一个例子
- Web项目添加Maven支持
- 关于SQL 行转列的办法
热门文章
- jmeter5实现文件上传接口测试
- 删除kubernetes-dashboard
- 思科S系列220系列交换机多个漏洞预警
- C++——文件的读写
- 最新 顺网科技java校招面经 (含整理过的面试题大全)
- springBoot--组合注解RestController,GetMapping,PostMapping
- 第35课.函数对象分析(";()";重载)
- [学习笔记] 在Eclipse中导出可以直接运行的jar,依赖的jar在子目录中
- HanLP-基于HMM-Viterbi的人名识别原理介绍
- Pandas 读取超过 65536 行的 Excel 文件