当前位置:网站首页>分子个数 数论(欧拉函数 前缀和
分子个数 数论(欧拉函数 前缀和
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;
}
边栏推荐
猜你喜欢
CAS: 178744-28-0, mPEG-DSPE, DSPE-mPEG, methoxy-polyethylene glycol-phosphatidylethanolamine supply
【杂项】通过Excel为字符串产生条码
LYVE1抗体丨Relia Tech LYVE1抗体解决方案
国内首发可视化智能调优平台,小龙带你玩转KeenTune UI
一文搞定 SQL Server 执行计划
XSLT – 服务器端概述
Fluorescein-PEG-CLS, cholesterol-polyethylene glycol-fluorescein scientific research reagent
Node.js的基本使用(三)数据库与身份认证
JVM垃圾回收总结(未完待续)
小身材有大作用——光模块基础知识(一)
随机推荐
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
Creo 9.0在草图环境中创建坐标系
2021年数据泄露成本报告解读
Creo 9.0二维草图的诊断:加亮开放端点
Three.js入门详解
代码重构:面向单元测试
The problem of disorganized data output by mnn model
[Paper Reading] TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
Install third-party packages via whl
栈的压入、弹出序列
MPLS综合实验
Super perfect version of the layout have shortcut, background replacement (solve the problem of opencv Chinese path)
(PC+WAP)织梦模板不锈钢类网站
C语言实验十五 文件
用两个栈模拟队列
HNUCM 2022年暑假ACM搜索专项练习
Pytest学习-skip/skipif
跨域的学习
The Chinese Valentine's Day event is romantically launched, don't let the Internet slow down and miss the dark time
Jmeter-参数化