记录编号 375085 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 2618.[HZOI 2015]月刊少女驴蛋蛋 最终得分 100
用户昵称 YGOI_真神名曰驴蛋蛋 是否通过 通过
代码语言 C++ 运行时间 44.449 s
提交时间 2017-02-24 17:46:57 内存使用 0.39 MiB
显示代码纯文本
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
inline int input() {
	static int c,t;static int k;k=0;t=1;
	do c=getchar(); while((c<'0'||c>'9')&&c!='-');
	if(c=='-')c=getchar(),t=-1;
	do k=k*10+c-'0',c=getchar(); while(c>='0'&&c<='9');
	return k*t;
}
//#define DEBUG
#define STATIC
namespace LONGER {
	#ifdef DEBUG
		int memory=0;
	#endif
	const int LOWBIT=10000;
	const int MAXN=1000;
	struct UnsignedLonger;
	inline UnsignedLonger operator +(const UnsignedLonger&,const UnsignedLonger&);
	inline UnsignedLonger operator -(const UnsignedLonger&,const UnsignedLonger&);
	inline UnsignedLonger operator *(const UnsignedLonger&,const UnsignedLonger&);
	inline UnsignedLonger operator /(const UnsignedLonger&,const UnsignedLonger&);
	inline UnsignedLonger operator %(const UnsignedLonger&,const UnsignedLonger&);
	inline UnsignedLonger operator <<(const UnsignedLonger&,const int&);
	inline UnsignedLonger operator >>(const UnsignedLonger&,const int&);
	inline UnsignedLonger operator & (const UnsignedLonger&,const int&);
	inline UnsignedLonger operator | (const UnsignedLonger&,const int&);
	inline UnsignedLonger operator ^ (const UnsignedLonger&,const int&);
	inline bool operator ==(const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator !=(const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator <=(const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator >=(const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator > (const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator < (const UnsignedLonger&,const UnsignedLonger&);
	inline bool operator ! (const UnsignedLonger&);
	inline UnsignedLonger input(FILE*);
	inline UnsignedLonger sinput(const char*);
	inline void print(const UnsignedLonger&,const char&,const int&,FILE*);
	inline void swap(UnsignedLonger&,UnsignedLonger&);
	inline int c_int(const UnsignedLonger&);
	inline std::ostream& operator <<(std::ostream&,const UnsignedLonger&);
	inline std::istream& operator >>(std::istream&,        UnsignedLonger&);
	struct UnsignedLonger{
		#ifndef STATIC 
		int *x,len;
		#else 
		int x[MAXN],len;
		#endif
		inline UnsignedLonger();
		inline ~UnsignedLonger();
		inline UnsignedLonger(int);
		inline UnsignedLonger(long long);
		inline UnsignedLonger(const char*);
		inline UnsignedLonger(const UnsignedLonger&);
		inline void update();
		inline int&operator [](const int&);
		inline UnsignedLonger& operator  =(int);
		inline UnsignedLonger& operator  =(long long);
		inline UnsignedLonger& operator  =(const char*);
		inline UnsignedLonger& operator  =(const UnsignedLonger&);
		inline UnsignedLonger& operator +=(const UnsignedLonger&);
		inline UnsignedLonger& operator *=(const UnsignedLonger&);
		inline UnsignedLonger& operator -=(const UnsignedLonger&);
		inline UnsignedLonger& operator /=(const UnsignedLonger&);
		inline UnsignedLonger& operator %=(const UnsignedLonger&);
		inline UnsignedLonger& operator ++();
		inline UnsignedLonger  operator ++(int);
		inline UnsignedLonger& operator --();
		inline UnsignedLonger  operator --(int);
		inline UnsignedLonger& operator >>=(const int&);
		inline UnsignedLonger& operator <<=(const int&);
		inline UnsignedLonger& operator &=(const int&);
		inline UnsignedLonger& operator ^=(const int&);
		inline UnsignedLonger& operator |=(const int&);
		inline int input(FILE*);
		inline int sinput(const char*);
		inline void print(const char&,const int&,FILE*)const;
		inline void swap(UnsignedLonger&);
		inline int c_int()const;
		//inline operator bool() const;
	};
	inline UnsignedLonger operator + (const UnsignedLonger&a,const UnsignedLonger&b) {
		UnsignedLonger c=0;
		c.len=std::max(a.len,b.len);
		for(int i=0;i<c.len;++i) {
			c.x[i]=a.x[i]+b.x[i];
		}c.update();
		return c;
	}
	inline UnsignedLonger operator -(const UnsignedLonger&a,const UnsignedLonger&b) {
		assert(a>=b);
		UnsignedLonger c;c.len=a.len;
		for(int i=0;i<c.len;++i) {
			c.x[i]+=a.x[i]-b.x[i];
			if(c.x[i]<0) {
				c.x[i]+=LOWBIT;
				--c.x[i+1];
			}
		}c.update();
		return c;
	}
	inline UnsignedLonger operator *(const UnsignedLonger&a,const UnsignedLonger&b) {
		UnsignedLonger c=0;
		c.len=a.len+b.len;
		#ifdef FastMuler
		if(a.len*b.len>600000) {
			COMPLEX::mul(a.x,b.x,c.x,std::max(a.len,b.len));
			c.update();
			return c;
		}
		#endif
		typedef long long TYPE;
		for(int i=0;i<a.len;++i) {
			for(int j=0;j<b.len;++j) {
				if(c.x[i+j]+a.x[i]*b.x[j]<0) {
					printf("%d %d %d\n",c.x[i+j],a.x[i],b.x[j]);
					assert(0);
				}
				c.x[i+j]+=a.x[i]*b.x[j];
				if(c.x[i+j]>LOWBIT) {
					c.x[i+j+1]+=c.x[i+j]/LOWBIT;
					c.x[i+j]%=LOWBIT;
				}
			}
		}c.update();
		return c;
	}
	inline UnsignedLonger operator /(const UnsignedLonger&a,const UnsignedLonger&b) {
		if(a<b)return 0;
		assert(!!b);
		UnsignedLonger c,d=b,e=a;
		c.len=a.len-b.len+1;
		d<<=c.len;
		for(int i=c.len-1;i>=0;--i) {
			d>>=1;
			while(e>=d){
				++c.x[i];
				e-=d;
			}
		}c.update();
		return c;
	}
	inline UnsignedLonger operator %(const UnsignedLonger&a,const UnsignedLonger&b) {
		return a-(a/b)*b;
	}
	inline UnsignedLonger operator <<(const UnsignedLonger &a,const int&b) {
		UnsignedLonger c;
		for(int i=0;i<a.len;++i) {
			if(i+b<MAXN)c.x[i+b]=a.x[i];
		}c.len=std::min(a.len+b,MAXN);
		return c;
	}
	inline UnsignedLonger operator >>(const UnsignedLonger&a,const int&b) {
		UnsignedLonger c;
		for(int i=b;i<a.len;++i) {
			if(i-b>=0)c.x[i-b]=a.x[i];
		}c.len=std::max(a.len-b,1);
		return c;
	}
	inline UnsignedLonger operator &(const UnsignedLonger&a,const int&b) {
		if(b>LOWBIT||b<0) {
			printf("I have not write and with %d:)\n",b);
			abort();
		}UnsignedLonger c=a;c.x[0]&=b;
		return c;
	}
	inline UnsignedLonger operator |(const UnsignedLonger&a,const int&b) {
		if(b>LOWBIT||b<0) {
			printf("I have not write or with %d:)\n",b);
			abort();
		}UnsignedLonger c=a;c.x[0]|=b;
		return c;
	}
	inline UnsignedLonger operator ^(const UnsignedLonger&a,const int&b) {
		if(b>LOWBIT||b<0) {
			printf("I have not write xor with %d:)\n",b);
			abort();
		}UnsignedLonger c=a;c.x[0]^=b;
		return c;
	}
	inline bool operator ==(const UnsignedLonger&a,const UnsignedLonger&b) {
		if(a.len!=b.len)return false;
		for(int i=a.len-1;i>=0;--i) {
			if(a.x[i]!=b.x[i])
				return false;
		}return true;
	}
	inline bool operator < (const UnsignedLonger&a,const UnsignedLonger&b) {
		if(a.len!=b.len)return a.len<b.len;
		for(int i=a.len-1;i>=0;--i) {
			if(a.x[i]!=b.x[i])
				return a.x[i]<b.x[i];
		}return false;
	}
	inline bool operator <=(const UnsignedLonger&a,const UnsignedLonger&b) {
		if(a.len<b.len)return true;
		for(int i=a.len-1;i>=0;--i) {
			if(a.x[i]<b.x[i])return true;
			if(a.x[i]>b.x[i])return false;
		}return true;
	}
	inline bool operator !=(const UnsignedLonger&a,const UnsignedLonger&b) {
		return !(a==b);
	}
	inline bool operator >(const UnsignedLonger&a,const UnsignedLonger&b) {
		return b<a;
	}
	inline bool operator >=(const UnsignedLonger&a,const UnsignedLonger&b) {
		return b<=a;
	}
	bool operator !(const UnsignedLonger&a) {
		return a.len==1&&a.x[0]==0;
	}
	inline UnsignedLonger input(FILE*in=stdin) {
		UnsignedLonger x;x.input(in);
		return x;
	}
	inline void print(const UnsignedLonger&a,const char&end=-1,const int&p=0,FILE*out=stdout) {
		a.print(end,p,out);
	}
	inline void swap(UnsignedLonger&a,UnsignedLonger&b) {
		std::swap(a.len,b.len);
		std::swap(a.x,b.x);
	}
	inline int c_int(const UnsignedLonger&a) {
		return a.x[1]*10000+a.x[0];
	}
	inline std::ostream& operator <<(std::ostream& pout,const UnsignedLonger&a) {
		pout<<a.x[a.len-1];
		for(int i=a.len-2;i>=0;--i) {
			int k=LOWBIT/10;
			while(k!=1&&a.x[i]<k) {
				pout<<'0';
				k/=10;
			}pout<<a.x[i];
		}return pout;
	}
	inline std::istream& operator >>(std::istream&pin,UnsignedLonger&a) {
		static char *sp=new char [MAXN*5];
		pin>>sp;
		a.sinput(sp);
		return pin;
	}
	inline UnsignedLonger::UnsignedLonger() {
		#ifndef STATIC
			#ifdef DEBUG
				printf("new memory of %d\n",MAXN);
				memory+=MAXN;
				assert(memory<1000000);
			#endif
		x=new int [MAXN];
		#endif
		memset(x,0,sizeof(int)*MAXN);
		len=1;
	}
	inline UnsignedLonger::UnsignedLonger(int z) {
		//printf("--->%d\n",z);
		#ifndef STATIC
			#ifdef DEBUG
				printf("new memory of %d\n",MAXN);
				memory+=MAXN;
				assert(memory<1000000);
			#endif
			x=new int[MAXN];
		#endif
		memset(x,0,sizeof(int)*MAXN);
		len=0;
		do {
			x[len++]=z%LOWBIT;
			z/=LOWBIT;
		}while(z);
	}
	inline UnsignedLonger::UnsignedLonger(long long z) {
		//printf("--->%d\n",z);
		#ifndef STATIC
			#ifdef DEBUG
				printf("new memory of %d\n",MAXN);
				memory+=MAXN;
				assert(memory<1000000);
			#endif
			x=new int[MAXN];
		#endif
		memset(x,0,sizeof(int)*MAXN);
		len=0;
		do {
			x[len++]=z%LOWBIT;
			z/=LOWBIT;
		}while(z);
	}
	inline UnsignedLonger::UnsignedLonger(const char*s) {
		#ifndef STATIC
			#ifdef DEBUG
				printf("new memory of %d\n",MAXN);
				memory+=MAXN;
				assert(memory<1000000);
			#endif
			x=new int[MAXN];
		#endif
		len=0;
		memset(x,0,sizeof(int)*MAXN);
		if(strcmp(s,"input")==0) {
			this->input(stdin);
		}else sinput(s);
	}
	inline UnsignedLonger::UnsignedLonger(const UnsignedLonger&a) {
		#ifndef STATIC
			#ifdef DEBUG
				printf("new memory of %d\n",MAXN);
				memory+=MAXN;
				assert(memory<1000000);
			#endif
			x=new int [MAXN];
		#endif
		len=a.len;
		memcpy(x,a.x,sizeof(int)*MAXN);
	}
	inline UnsignedLonger::~UnsignedLonger() {
		#ifndef STATIC
			#ifdef DEBUG
				printf("lost memory of %d\n",MAXN);
				memory-=MAXN;
				assert(memory<1000000);
			#endif
			delete[] x;
		#endif
		len=0;
	}
	inline UnsignedLonger& UnsignedLonger::operator = (const UnsignedLonger&a){
		len=a.len;
		memcpy(x,a.x,sizeof(int)*MAXN);
		return *this;
	}
	inline UnsignedLonger& UnsignedLonger::operator =(int z){
		memset(x,0,sizeof(int)*MAXN);
		len=0;
		do {
			x[len++]=z%LOWBIT;
			z/=LOWBIT;
		}while(z);
		return *this;
	}
	inline UnsignedLonger& UnsignedLonger::operator =(long long z){
		memset(x,0,sizeof(int)*MAXN);
		len=0;
		do {
			x[len++]=z%LOWBIT;
			z/=LOWBIT;
		}while(z);
		return *this;
	}
	inline UnsignedLonger& UnsignedLonger::operator =(const char*s) {
		if(strcmp(s,"input")==0){
			this->input(stdin);
		}else sinput(s);
		return *this;
	}
	inline int& UnsignedLonger::operator [] (const int&i) {
		return x[i];
	}
	inline UnsignedLonger& UnsignedLonger::operator +=(const UnsignedLonger&a) {
		return (*this)=(*this)+a;
	}
	inline UnsignedLonger& UnsignedLonger::operator *=(const UnsignedLonger&a) {
		return (*this)=(*this)*a;
	}
	inline UnsignedLonger& UnsignedLonger::operator -=(const UnsignedLonger&a) {
		return (*this)=(*this)-a;
	}
	inline UnsignedLonger& UnsignedLonger::operator /=(const UnsignedLonger&a) {
		return (*this)=(*this)/a;
	}
	inline UnsignedLonger& UnsignedLonger::operator %=(const UnsignedLonger&a) {
		return (*this)=(*this)%a;
	}
	inline UnsignedLonger& UnsignedLonger::operator ++() {
		return (*this)+=1;
	}
	inline UnsignedLonger& UnsignedLonger::operator --() {
		return (*this)-=1;
	}
	inline UnsignedLonger UnsignedLonger::operator ++(int) {
		UnsignedLonger p=(*this);
		(*this)+=1;
		return p;
	}
	inline UnsignedLonger UnsignedLonger::operator --(int) {
		UnsignedLonger p=(*this);
		(*this)-=1;
		return p;
	}
	inline UnsignedLonger& UnsignedLonger::operator >>=(const int&i) {
		return (*this)=(*this)>>i;
	}
	inline UnsignedLonger& UnsignedLonger::operator <<=(const int&i) {
		return (*this)=(*this)<<i;
	}
	inline UnsignedLonger& UnsignedLonger::operator &=(const int&i) {
		return (*this)=(*this)&i;
	}
	inline UnsignedLonger& UnsignedLonger::operator ^=(const int&i) {
		return (*this)=(*this)^i;
	}
	inline UnsignedLonger& UnsignedLonger::operator |=(const int&i) {
		return (*this)=(*this)|i;
	}
	//inline UnsignedLonger::operator bool()const {
	//  return !!(*this);
	//}
	inline void UnsignedLonger::update() {
		for(int i=0;i<=len;++i) {
			if(x[i]>LOWBIT){
				x[i+1]+=x[i]/LOWBIT;
				x[i]%=LOWBIT;
			}if(x[i]<0) {
				x[i]+=LOWBIT;
				x[i+1]-=1;
			}
		}
		while(len<MAXN&&x[len]!=0){++len;}
		while(len>1&&x[len-1]==0)--len;
		if(len==0)len=1;
	}
	inline void UnsignedLonger::print(const char&end=-1,const int&p=0,FILE*out=stdout) const{
		if(p){
			fprintf(out,"[%d|%d]",len,x);
			fprintf(out,"%d ",x[len-1]);
			for(int i=len-2;i>=0;--i){
				fprintf(out,"%04d ",x[i]);
			}if(end!=-1)printf("%c",end);
		}else {
			fprintf(out,"%d",x[len-1]);
			for(int i=len-2;i>=0;--i){
				fprintf(out,"%04d",x[i]);
			}if(end!=-1)printf("%c",end);
		}
	}
	inline int UnsignedLonger::input(FILE*in=stdin) {
		static char*sc=new char[MAXN*5];
		fscanf(in,"%s",sc);
		return sinput(sc); 
	}
	inline int UnsignedLonger::sinput(const char *sp="") {
		int les=strlen(sp);
		if(les==0)return 0;
		static char *sc=new char [MAXN*5];
		memcpy(sc,sp,sizeof(char)*(les));sc[les]='\0';
		for(int i=0;i<les;++i) {
			if(i<les-i-1)
				std::swap(sc[i],sc[les-i-1]);
			else break;
		}
		for(int i=0;i+4<les;i+=4) {
			char *p=sc+i;
			for(int j=0;j<2;++j) {
				std::swap(p[j],p[4-j-1]);
			}
		}int res=std::max(les-(les%4==0?4:les%4),0);
		for(int i=0;res+i<les;++i){
			if(res+i<les-i-1){
				std::swap(sc[res+i],sc[les-i-1]);
			}else break;
		}
		memset(x,0,sizeof(int)*MAXN);
		for(int i=0;i<res;i+=4) {
			sscanf(sc+i,"%4d",x+(i>>2));
		}sscanf(sc+res,"%d",x+(res>>2));
		len=les/4+(les%4!=0);this->update();
		return 1;
	}
	inline void UnsignedLonger::swap(UnsignedLonger&a) {
		LONGER::swap((*this),a);
	}
	inline int UnsignedLonger::c_int()const {
		return LONGER::c_int(*this);
	}
}
typedef LONGER::UnsignedLonger ext;
const int MAXLEN=10000;
struct Poly {
	long long c[MAXLEN];
	int N;
	Poly() {memset(c,0,sizeof(c));N=1;}
	Poly(int k) {
		N=1;
		memset(c,0,sizeof(c));
		c[0]=k;
	}
	Poly(int len,bool set,int step=1) {
		N=len*step;
		memset(c,0,sizeof(c));
		if(set){
			for(int i=0;i<len;i++)
				c[i*step]=1;
			while(N>1&&c[N-1]==0)--N;
		}
	}
	long long & operator [](const int&i){return c[i];}
	const long long & operator [](const int&i) const{return c[i];}
	void print(const char*end=NULL) const {
		printf("N:%d ",N);
		for(int i=0;i<N;++i) {
			if(i!=0&&c[i]==0)continue;
			else if(i==0&&c[i]>0)printf("%lld",c[i]);
			else if(i==0&&c[i]<0)printf("-%lld",c[i]);
			else if(i==1&&c[i]==1)printf("+z");
			else if(i==1&&c[i]==-1)printf("-z");
			else if(i==1&&c[i]>0)printf("+%lldz",c[i]);
			else if(i==1&&c[i]<0)printf("%lldz",c[i]);
			else if(c[i]==1)printf("+z^%d",i);
			else if(c[i]==-1)printf("-z^%d",i);
			else if(c[i]>0)printf("+%lldz^%d",c[i],i);
			else printf("%lldz^%d",c[i],i);
			printf("\n");
		}if(end!=NULL)printf("%s",end);
	}
	void check()const {
		assert(N!=0);
		for(int i=0;i<N;++i) 
			assert(c[i]>=0);
	}
};
Poly operator + (const Poly&a,const Poly&b) {
	Poly c(std::max(a.N,b.N),0);
	for(int i=0;i<c.N;++i) {
		c[i]=a[i]+b[i];
	}return c;
}
Poly operator - (const Poly&a,const Poly&b) {
	Poly c(std::max(a.N,b.N),0);
	for(int i=0;i<c.N;++i) {
		c[i]=a[i]-b[i];
	}
	while(c.N>1&&c[c.N-1]==0)c.N--;
	return c;
}
Poly operator *(const Poly&a,const Poly&b) {
	Poly c(a.N+b.N-1,0);
	for(int i=0;i<a.N;++i) {
		if(a[i]!=0)
		for(int j=0;j<b.N;++j) {
			c[i+j]+=a[i]*b[j];
		}
	}return c;
}
int gcd(int a,int b) {return (b==0)?a:gcd(b,a%b);}
int lcm(int a,int b) {return a/gcd(a,b)*b;}
const int MAXN=40;
int a[MAXN];
Poly g=1;
ext C(ext n,int m) {
	ext ans=1;
	//n.print('\n');
	for(int i=1;i<=m;++i) {
		//(n-i+1).print('\n');
		ans*=n-i+1;
		ans/=i;
	}//printf("ans:=");ans.print('\n');
	return ans;
}
FILE *IN=stdin,*OUT=stdout;
int SPFA=0;
int doing() {
	int N;
	fscanf(IN,"%d",&N);N+=1;
	if(N==0){fputs("1",OUT);return 0;}
	ext cc=LONGER::input(IN);
	g=1;
	a[1]=1;
	for(int i=2;i<=N;++i) {
		fscanf(IN,"%d",&a[i]);
	}
	int P=1,G=a[2];
	for(int i=2;i<=N;++i) {
		G=gcd(G,a[i]);
	}//printf(">>>%d\n",G);
	for(int i=2;i<=N;++i) {
		a[i]/=G;
	}cc/=G;
	for(int i=1;i<=N;++i) {
		P=lcm(P,a[i]);
	}//printf("%d",P);
	for(int i=1;i<=N;++i) {
		//g.print("\n");
		g=g*Poly(P/a[i],1,a[i]);
	}g.check();
	int M=N-1;
	ext q=cc/P;
	int r=(cc%P).c_int();
	ext ans=0;
	ext ic=C(q+=M,M);
	for (;r<g.N&&q>=M;) {
	
		//printf("True %d\n",++SPFA);
		//ic.print('\n',-1);
		//ext(g[r]).print('\n',-1);
		ext c=ic*g[r];

		ans+=ic*g[r];
		if(q!=M) {
			ic*=q-M;
			ic/=q;
		}
		//q.print('\n');
		--q;
		r+=P;
	}
	ans.print(-1,0,OUT);
	return 0;
}
int main() {
	char str[100];
	sprintf(str,"TSUMANNAIKOTO.in");
	IN=fopen(str,"r");
	sprintf(str,"TSUMANNAIKOTO.out");
	OUT=fopen(str,"w");
	doing();
	return 0;
}