题意:
有限制的构造一些序列,使它们gcd=1 (好吧懒得概括)
题解:
因为最后一个数是确定的,所以其它数不能有都有m的质因数。
显然容斥。
洛谷上有题不用高精度,不想写高精,精A。
code(低精):
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
LL a[35],num=0;
LL n,m;
LL ans=0;
LL fow(LL a,LL b)
{
LL ans=1;
while(b) {if(b&1) ans*=a;a*=a;b>>=1;}
return ans;
}
void dfs(LL tot,LL x,LL t)
{
if(x>num) {ans+=(t?1:-1)*fow(m/tot,n);return;}
dfs(tot*a[x],x+1,t^1);dfs(tot,x+1,t);
}
int main()
{
scanf("%lld %lld",&n,&m);
LL x=m;
LL len=sqrt(m);
for(LL i=2;i<=len;i++)
if(x%i==0) {a[++num]=i;while(x%i==0) x/=i;}
if(x!=1) a[++num]=x;
dfs(1,1,1);
printf("%lld",ans);
}