链接 https://nanti.jisuanke.com/t/31456

参考题解  https://blog.csdn.net/ftx456789/article/details/82590044

 #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
const int maxn=1e6+;
typedef long long ll;
map<ll,ll> ma,yin;
int check[maxn],prime[maxn],mu[maxn];
void Mobius(int N)//莫比乌斯函数线性筛
{
int pos=;mu[]=;
for (int i = ; i <= N ; i++)
{
if (!check[i])
prime[pos++] = i,mu[i]=-;
for (int j = ; j < pos && i*prime[j] <= N ; j++)
{
check[i*prime[j]] = ;
if (i % prime[j] == )
{
mu[i*prime[j]]=;
break;
}
mu[i*prime[j]]=-mu[i];
}
}
for(int i=;i<=N;i++)
mu[i]+=mu[i-];
}
ll sum(ll a)
{
if(a<=1e6)
return mu[a];
if(ma.count(a))
return ma[a];
ll temp=;
for(ll i=;i<=a;)
{
ll t=a/i;
ll k=a/t;
temp-=(k-i+)*sum(t);
i=k+;
}
return ma[a]=temp;
}
void shai(ll n)//筛素因子
{
ll x=n;
for(ll i=;i*i<=x;i++)
{
while(x%i==)
{
yin[i]++;
x/=i;
}
}
if(x>)yin[x]++;
}
ll solve(ll n,ll m)
{
if(m==)return ;//m等于0就是0喽
if(n==)return sum(m);//n等于1 就是莫比乌斯函数 u 的前 m 项和
for(auto it:yin)
{
if(n%it.fi==)
{
return solve(n,m/it.fi)-solve(n/it.fi,m);
}
}
}
int main()
{
Mobius(1e6);
ll n,m;
cin>>n>>m;
shai(m);
for(auto it:yin)
if(it.se>)
{
cout<<<<endl;
return ;
}
cout<<solve(m,n)<<endl;
return ;
}

ACM-ICPC 2018 徐州赛区网络预赛

ACM-ICPC 2018 徐州赛区网络预赛 D 杜教筛 前缀和的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  3. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    Mur loves hash algorithm, and he sometimes encrypt another one's name, and call him with that encryp ...

  9. ACM-ICPC 2018 徐州赛区网络预赛(8/11)

    ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...

随机推荐

  1. KendoUI Grid Pager部分 Nan-Nan of x Items

    相关问题: http://stackoverflow.com/questions/23941065/pager-error-in-kendo-gridnan-nan-of-1-items http:/ ...

  2. TensorFlow 安装 Win10 Python+GPU

    前叙:有灵魂的程序都是每一个程序员的最终目标.TensorFlow了解下? 打算花几个月学机器学习,TensorFlow是很好的选择,折腾了会环境,略有心得分享下. 环境:win10 Python:3 ...

  3. Ubuntu16.04常用操作命令总结ing

    查看软件安装目录:whereis 软件名称(如:whereis mysql,where is sqlite3等) 安装软件:apt/apt-get install 软件名称(如:apt/apt-get ...

  4. sklearn之SVC

    sklearn.svm.SVC(C=1.0, kernel='rbf', degree=3, gamma='auto', coef0=0.0, shrinking=True, probability= ...

  5. c:if标签--判断不为空和其他的值判断

      用<c:if test=""></c:if>标签时 <c:if test="${sl.chc_status==1 }"> ...

  6. 全新Ubentu系统没有make,gcc命令解决办法

    一定要记得先update sudo apt-get update 然后输入下述命令即可 sudo apt-get install make sudo apt-get install gcc

  7. linux(php环境) 安装ffmpeg

    实现上传视频获取视频的第一帧当做视频封面 1.安装ffmpeg ffmpeg的下载链接  https://ffmpeg.org/download.html 解压安装包 tar -jxvf ffmpeg ...

  8. 开门人和关门人(结构体+sort)

    每天第一个到机房的人要把门打开,最后一个离开的人要把门关好.现有一堆杂乱的机房签 到.签离记录,请根据记录找出当天开门和关门的人.    Input 测试输入的第一行给出记录的总天数N ( > ...

  9. Uva 11212 编辑书稿(迭代加深搜索)

    题意: 给定N个数的序列, 希望将它排列成1~N, 可以用剪切.粘贴来完成任务, 每次可以剪切一段连续的自然段, 粘贴时按照顺序粘贴. #include <bits/stdc++.h> # ...

  10. MyBatis 3 学习

    MyBatis是一款优秀的持久化框架,支持定制化SQL.存储过程以及高级映射.MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获得结果集.MyBatis可以使用简单的XML或注解来配置和映 ...