题解 P5887 【Ringed Genesis】
在一个长度为
于是可以得出方法。
令
对于每一个
最后检查
代码如下:
#include<cstdio>
using namespace std;
#define re register
const int Mxdt=500;
inline char gc(){
static char buf[Mxdt],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read()
{
int res=0;char ch=gc();
while(ch<'0'||ch>'9')ch=gc();
while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+(ch^48),ch=gc();
return res;
}
int n,m,a[1000002],p,b,ans;
bool v[1000002];
inline int gcd(re int x,re int y){
return y?gcd(y,x%y):x;
}
int main(){
n=read();
m=read();
p=read();
p=gcd(p,n);
for(re int i=1;i<=m;++i)v[read()%p]=1;
for(re int i=1;i<=n;++i)if(!v[i%p])++ans;
printf("%d",ans);
}