当前位置:网站首页>分子个数 数论(欧拉函数 前缀和
分子个数 数论(欧拉函数 前缀和
2022-08-03 23:58:00 【Rachel caramel】
题面:

思路:
题目的意思其实就是求 欧拉函数的前缀和
∑ i = 2 d ∑ j = 1 j = i − 1 [ gcd ( j , i ) = 1 ] 注: [ gcd ( j , i ) = 1 ] 的含义为: 若 gcd ( j , i ) = 1 , [ gcd ( j , i ) = 1 ] = 1 若 gcd ( j , i ) ≠ 1 , [ gcd ( j , i ) = 1 ] = 0 \sum_{i=2}^{d} \sum_{j=1}^{j=i-1}[\gcd(j,i)=1]\\ \text{注:}[\gcd(j,i)=1] \text{的含义为:}\\ \text{若}\gcd(j,i)=1,[\gcd(j,i)=1]=1\\ \text{若}\gcd(j,i)\not=1,[\gcd(j,i)=1]=0\\ i=2∑dj=1∑j=i−1[gcd(j,i)=1]注:[gcd(j,i)=1]的含义为:若gcd(j,i)=1,[gcd(j,i)=1]=1若gcd(j,i)=1,[gcd(j,i)=1]=0
欧拉函数的各种推导可见欧拉函数总结
代码:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const int maxn=111111;
int d;
long long ans,phi[maxn];
void handle(int n)
{
for(int i=1;i<=n;i++) phi[i]=i;
for(int i=2;i<=n;i++)
{
if(phi[i]==i)
{
for(int j=i;j<=n;j+=i) phi[j]=phi[j]-phi[j]/i;
}
}
}
int main()
{
scanf("%d",&d);
handle(d);
for(int i=2;i<=d;i++) ans+=phi[i];
printf("%lld\n",ans);
return 0;
}
边栏推荐
- 超级完美版布局有快捷键,有背景置换(解决opencv 中文路径问题)
- Free自由协议系统开发
- A simple understanding of TCP, learn how to shake hands, wave hands and various states
- The Beijing E-sports Metaverse Forum was successfully held
- 【LeetCode】最长回文子序列(动态规划)
- leetcode/子串中不能有重复字符的最长子串
- RSS订阅微信公众号初探-feed43
- 响应式织梦模板餐饮酒店类网站
- 初始 List 接口
- Minimized installation of debian11
猜你喜欢

After building the pytorch environment, the pip and conda commands cannot be used

查看CUDA、pytorch等的版本号

Node.js的基本使用(三)数据库与身份认证

我的祖国

Install third-party packages via whl

Read FastDFS in one article

The problem of disorganized data output by mnn model

免费的公共WiFi不要乱连,遭中间人攻击了吧?

利用matlab求解线性优化问题【基于matlab的动力学模型学习笔记_11】

国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
随机推荐
rsync basic usage
射频芯片ATE测试从入门到放弃之参数测试
Salesforce的中国区业务可能出现新变化,传言可能正在关闭
leetcode/子串中不能有重复字符的最长子串
2021年数据泄露成本报告解读
Nanoprobes 棕榈酰纳米金相关说明书
A simple understanding of TCP, learn how to shake hands, wave hands and various states
3D Semantic Segmentation - 2DPASS
全球首款量产,获定点最多!这家AVP Tier1如何实现领跑?
北京电竞元宇宙论坛活动顺利召开
用队列模拟实现栈
JS获得URL超链接的参数值
逆波兰表达式求值
Shell编程之循环语句与函数
Shell 用法梳理总结
It will invest about 200 billion US dollars in the United States in 20 years, and Samsung Electronics looks so handsome
Why Flutter Flutter of tutorials is the best choice for business?
MCS-51单片机,定时1分钟,汇编程序
Install third-party packages via whl
Use tf.image.resize() and tf.image.resize_with_pad() to resize images