跳到正文

剪贴板

剪贴板 ad1bwur6

原文
剪贴板信息

剪贴板信息

收录
更新
C++
/*
  author: honglan0301
  Sexy_goodier _ xiaoqing
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cctype>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <cmath>
#include <set>
#include <bitset>
#include <assert.h>
using namespace std;

//namespace Fread{const int SIZE=1<<20;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return*S++;}}using namespace Fread;namespace Fwrite{const int SIZE=1<<20;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}using namespace Fwrite;
//#define getchar Fread::getchar
//#define putchar Fwrite::putchar

namespace Fastio{struct Reader{template<typename T>Reader&operator>>(T&x){x=0;short f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();x*=f;return*this;}Reader&operator>>(double&x){x=0;double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(long double&x){x=0;long double t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(__float128&x){x=0;__float128 t=0;short f=1,s=0;char c=getchar();while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else{x*=f;return*this;}while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}Reader&operator>>(char&c){c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();return*this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(string&str){str.clear();char c=getchar();while(c==' '||c=='\n'||c=='\r')c=getchar();while(c!=' '&&c!='\n'&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{const int Setprecision=6;typedef int mxdouble;template<typename T>Writer&operator<<(T x){if(x==0){putchar('0');return*this;}if(x<0)putchar('-'),x=-x;static short sta[40];short top=0;while(x>0)sta[++top]=x%10,x/=10;while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(long double x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(long double)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(__float128 x){if(x<0)putchar('-'),x=-x;mxdouble _=x;x-=(__float128)_;static short sta[40];short top=0;while(_>0)sta[++top]=_%10,_/=10;if(top==0)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_>0)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top>0)putchar(sta[top]+'0'),top--;return*this;}Writer&operator<<(char c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl//;fflush(stdout)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define B 22

int mod,n,g,vis[200005],op[1000005],a[1000005],cnt0,ans;
int cf[200005],bh[200005],vis1[200005],vis2[200005];

int ck(int x)
{
	memset(vis,0,sizeof(vis)); int nr=1; vis[nr]=1;
	for(int i=1;i<=mod-2;i++)
	{
		nr=(ll)nr*x%mod; if(vis[nr]) return 0; vis[nr]=1;
	}
	return 1;
}
bitset <200005> bt,nr,nb[25][25];
int mc[200005],cnt[200005],qc[200005],nd[25];

void cz()
{
	for(int i=1;i<mod-1;i++)
	{
		qc[(i*2)%(mod-1)]+=(qc[i]-1)/2; qc[i]-=((qc[i]-1)/2)*2;
	}
}
int gcd(int x,int y)
{
	return !y?x:gcd(y,x%y);
}
void init()
{
	for(int i=2;i<=B;i++)
	{
		if((mod-1)%i==0)
		{
			for(int j=0;j<mod-1;j++) nb[i][j%i][j]=1;
		}
	}
}
void getnd()
{
	for(int i=2;i<=B;i++)
	{
		if((mod-1)%i==0)
		{
			nd[i]=0;
			for(int j=0;j<i;j++)
			{
				int nc=(bt&nb[i][j]).count(); if(nc!=0&&nc!=(mod-1)/i) {nd[i]=1; break;}
			}
		}
	}
}

signed main()
{
	//freopen("number5.in","r",stdin);
	//freopen("number5.ans","w",stdout);
	cin>>mod>>n; for(int i=2;i<=mod;i++) if(ck(i)) {g=i; break;}
	for(int i=1;i<=n;i++) cin>>op[i]>>a[i],cnt0+=(a[i]==0); if(cnt0) ans=1;
	cf[0]=1; bh[1]=0; for(int i=1;i<=mod-2;i++) cf[i]=(ll)cf[i-1]*g%mod,bh[cf[i]]=i;
	vis1[bh[1]]=1;
	for(int i=1;i<=n;i++)
	{
		if(op[i]==0&&a[i]!=0) vis1[bh[a[i]]]=1;
		if(op[i]==1&&a[i]!=0) qc[bh[a[i]]]++;
	}
	for(int i=0;i<mod-1;i++) if(vis1[i]) bt[i]=1;
	for(int i=0;i<mod-1;i++) nr[i]=1; init(); getnd(); nd[1]=1;
	for(int i=1;i<=20;i++) cz();
	int cntt=0;
	for(int i=1;i<mod-1;i++)
	{
		//cout<<i<<" "<<qc[i]<<endl;
		if(!qc[i]) continue;
		int gd=gcd(i,mod-1); if(gd<=B&&!nd[gd]) continue;
		int lst=bt.count();
		for(int j=1;j<=qc[i];j++) bt|=(bt<<i)|(bt>>(mod-1-i)),bt&=nr;
		if(bt.count()==lst) continue;
		if(bt.count()==mod-1) break;
		getnd();
	}
	ans+=bt.count(); cout<<ans<<endl;
}