链接 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. React-Native 开发问题整理

    1.内嵌WebView,点击输入框后页面不自动上滚 <activity android:name=".MainActivity" android:label="@s ...

  2. SEO 第三章

    SEO第三章 本次课目标: 1.  掌握关键词的选取方法 2.  掌握关键词的竞争强度分析 3.  掌握关键词的拓展方法 一.关键词的选取 选择关键词的时候可以根据公司网站的定位,围绕公司的主营产品或 ...

  3. Python基础4 迭代器,生成器,装饰器,Json和pickle 数据序列化

    本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 1.列表生成式,迭代器&生成器 列表生成式 孩子,我现在有个需 ...

  4. LinuxMint 编译 LittlevGL GUI

    编译必须 安装arm-linux-gcc-4.4.3.tar.gz PC simulator You can try out the Littlev Graphics Library using on ...

  5. error C2143: 语法错误 : 缺少“;”(在“&”的前面)

    报错: error C2143: 语法错误 : 缺少“;”(在“&”的前面) 代码: #include <iostream> ostream & << (ost ...

  6. dos command

    dos command md 创建目录 rd 删除目录 cd\ 返回到根目录 cd.. 返回到上一级目录 cd 进入指定目录 dir 列出当前目录下的文件夹及文件 echo 文件内容>文件名称. ...

  7. BZOJ1232: [Usaco2008Nov]安慰奶牛cheer(最小生成树)

    题意:给一个图 需要找到一个子图使得所有点都连通 然后再选择一个点做为起点 走到每个点并回到起点 每条边,每个点被经过一次就要花费一次边权.点权 题解:肯定是找一颗最小生成树嘛 然后惊奇的发现 任意选 ...

  8. ie8兼容性

    ie8下不支持css的nth-child()样式解决方法一:使用jQuery的nth-child()方法例:$(".ability-head-list ul li:nth-child(1) ...

  9. java中的编译时与运行时

    ----?基础知识   -- 编译时 编译器将源代码翻译成机器能够读懂的代码,如java中就是翻译成jvm能够读懂的字节码文件.简单说,编译时就是机器帮我们检查代码是否有出现语法错误,关键字写错之类的 ...

  10. 嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=15873837810484552531 中的15-23讲

    #coding=gbk#嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=1587383 ...