https://www.luogu.org/problemnew/show/P3601

一道关于欧拉函数的题。

读完题目以后我们知道所谓的$aindao(x)=x- \phi (x) $。

对于x小的情况下我们当然可以用 枚举因子或者线型筛求得,然而x打了以后就数组装不下了。

注意区间大小,我们完全可以只求这一部分区间内的x的$ \phi (x) $,数字移一下位置就好了。

然而求没一个数的欧拉函数值时我们只用到了,小于等于$\sqrt x$的质因子(就想线性筛一样),所以我们只需要晒出小于$\sqrt r$的素数是什么,然后了枚举区间中每一个数的倍数然后用公式进行不断地更新就好了。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define LL long long
#define mod 666623333
LL prime[],vis[],tot,cnt,phi[];
LL l,r,ans;
void prepare()
{
for(int i=;i<=;i++)
{
if(!vis[i])prime[++tot]=i;
for(int j=;j<=tot&&prime[j]*i<=;j++)
{
vis[prime[j]*i]=;
if(i%prime[j]==)
{
// phi[i*prime[j]]=phi[i]*prime[j];
break;
}
// else phi[i*prime[j]]=phi[i]*phi[prime[j]];
}
}
}
LL A[],B[];
int main()
{
prepare();
scanf("%lld%lld",&l,&r);
for(LL i=;i<=r-l+;i++)phi[i]=B[i]=i+l-;
for(LL i=;i<=tot&&prime[i]*prime[i]<=r;i++)
{
LL lb=prime[i]*(l/prime[i]),rb=prime[i]*(r/prime[i]);
// cout<< lb<<" "<<rb<<"\n";
for(LL j=lb;j<=rb;j+=prime[i])
{
if(j>=l)
{
phi[j-l+]=phi[j-l+]/prime[i]*(prime[i]-);
while(B[j-l+]%prime[i]==)B[j-l+]/=prime[i];
}
}
} for(int i=;i<=r-l+;i++)
{
if(B[i]>)phi[i]=phi[i]/B[i]*(B[i]-); //剩下一堆大质数了。
ans+=l+i--phi[i];ans%=mod;
}
cout<<ans;
}

最新文章

  1. 用NPOI从DataBase到Excel &#39;2
  2. AOJ DSL_2_E Range Add Query (RAQ)
  3. [leetcode 37]sudoku solver
  4. Google Chrome开发者工具
  5. DPDK内存管理-----(一)初始化
  6. c#打印机设置,取得打印机列表及相应打印机的所有纸张格式
  7. Codeforces 296C Greg and Array
  8. Linux 下 的 cc 和 gcc
  9. Go学习笔记(一):Ubuntu 环境下Go的安装
  10. windows 7 下快速搭建php环境(windows7+IIS7+php+mysql)
  11. CodeForces 706B Interesting drink
  12. IDL 计算TVDI
  13. RAD Studio 2010 环境设置(转)
  14. W3CSchool闯关笔记(初级脚本算法)
  15. C#工具:防sql注入帮助类
  16. 十分钟入门 Less
  17. 再理解tcp backlog
  18. 基于Docker的负载均衡和服务发现
  19. day10 浅谈面向对象编程
  20. Proxy 代理模式 动态代理 cglib MD

热门文章

  1. Kali Linux 工具清单
  2. React中的代码分割
  3. thinkPHP5 tablib标签库自定义方法
  4. Serilog 是 ASP.NET Core 的一个插件,可以简化日志记录
  5. 转 event &#39;utl_file I/O&#39;:
  6. Jenkins+Gitlab+Ansible自动化部署(六)
  7. DevExpress PivotGrid 使用记录
  8. spark RPC详解
  9. 一般处理程序aspx
  10. java-web项目:用servlet监听器实现显示在线人数