链接 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. Android自定义zxing扫描界面的实现

    首先,我们需要导入zxing的jar文件,其次复制所需要的资源文件以及放入自己需要添加的资源文件,复制出源码的必要相关类文件.对布局文件进行一定的修改,再修改CaptureActivity与Viewf ...

  2. Android里的 ART、JIT、AOT、Dalvik之间有什么关系?

    ART.JIT.AOT.Dalvik之间有什么关系? JIT与Dalvik JIT是"Just In Time Compiler"的缩写,就是"即时编译技术", ...

  3. SQLite – GLOB子句

    SQLite – GLOB子句 .与LIKE不同,GLOB是大小写敏感的,它遵循语法的UNIX指定以下通配符. The asterisk sign (*) The question mark (?) ...

  4. chart 图片组件 生成后不能动态更新,需要销毁dom,从新载入 用 v-if 和 this.$nextTick(() => {

    <chart-box v-if="cbData1Bool" cb-text="基本概况" chartBoxSele="饼状图" :cb ...

  5. 暑假集训 || 状压DP

    emm 位操作实现技巧: 获得第i位的数据:  if(!(data & (1<< i)))  则data的第 i 位为0,else 为 1 设置第i位为1,data=(data | ...

  6. POJ - 3126 - Prime Path(BFS)

    Prime Path POJ - 3126 题意: 给出两个四位素数 a , b.然后从a开始,每次可以改变四位中的一位数字,变成 c,c 可以接着变,直到变成b为止.要求 c 必须是素数.求变换次数 ...

  7. 什么是PHP中的heredoc和nowdoc

    heredoc结构类似于双引号字符串,nowdoc结构是类似于单引号字符串的.nowdoc结构很像heredoc结构,但是 nowdoc不进行解析操作. 这种结构很适合用在不需要进行转义的PHP代码和 ...

  8. mysql查询表中最小可用id值

    今天在看实验室的项目时,碰到的一个问题,.先把sql语句扔出来 // 这条语句在id没有1时,不能得到正确的查询结果. select min(id+1) from oslist c where not ...

  9. Linux vsftpd服务

    vsftpd服务 由vsftpd包提供 不再由xinetd管理 用户认证配置文件:/etc/pam.d/vsftpd 服务脚本: /usr/lib/systemd/system/vsftpd.serv ...

  10. validate 常用的输入框校验

    记录一下angular可以直接用的输入框校验器,外加一个国内手机号码的校验 <!DOCTYPE html> <html> <head> <meta chars ...