QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19855#2601. Lucky TicketsExplodingKonjac#AC ✓372ms19312kbC++143.7kb2022-02-12 14:54:472022-05-06 07:21:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 07:21:50]
  • 评测
  • 测评结果:AC
  • 用时:372ms
  • 内存:19312kb
  • [2022-02-12 14:54:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#define OPENIOBUF

namespace FastIO
{
	class FastIOBase
	{
	 protected:
#ifdef OPENIOBUF
		static const int BUFSIZE=1<<22;
		char buf[1<<22];
		int buf_p=0;
#endif
		FILE *target;
	 public:
#ifdef OPENIOBUF
	 	virtual void flush()=0;
#endif
		FastIOBase(FILE *f): target(f){}
		~FastIOBase()=default;
	};

	class FastOutput: public FastIOBase
	{
#ifdef OPENIOBUF
	 public:
		inline void flush()
			{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	 protected:
		inline void __putc(char x)
		{
#ifdef OPENIOBUF
			buf[buf_p++]=x;if(buf_p>=BUFSIZE)flush();
#else
			putc(x,target);
#endif
		}
		template<typename T>
		void __write(const T &x)
		{
			if(x<0)	__putc('-'),__write(-x);
			else	{ if(x>9)__write(x/10);__putc(x%10+'0'); }
		}
	 public:
		FastOutput(FILE *f=stdout): FastIOBase(f){}
		inline FastOutput &operator <<(char x)
			{ return __putc(x),*this; }
		inline FastOutput &operator <<(const char *s)
			{ for(;*s;__putc(*(s++)));return *this; }
		inline FastOutput &operator <<(const string &s)
			{ return (*this)<<s.c_str(); }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastOutput &operator <<(const T &x)
			{ return __write(x),*this; }
		template<typename ...T>
		inline void writesp(const T &...x)
			{ int var[]={(this->operator<<(x),__putc(' '),0)...}; }
		template<typename ...T>
		inline void writeln(const T &...x)
			{ int var[]={(this->operator<<(x),__putc('\n'),0)...}; }
	}qout;

	class FastInput: public FastIOBase
	{
#ifdef OPENIOBUF
	 public:
		inline void flush()
			{ fread(buf,1,BUFSIZE,target),buf_p=0; }
#endif
	 private:
		char ch,sym;
		static char str_buf[1<<22];
	 protected:
	 	inline char __getc()
		{
#ifdef OPENIOBUF
			if(!buf_p || buf_p>=BUFSIZE)flush();return buf[buf_p++];
#else
			return getc(target);
#endif
		}
	 public:
		FastInput(FILE *f=stdin): FastIOBase(f){}
		inline char getchar()
			{ return __getc(); }
		inline FastInput &operator >>(char &x)
			{ while((x=__getc())<33);return *this; }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastInput &operator >>(T &x)
		{
			x=0,sym=1;
			while((ch=__getc())<33);if(ch=='-')sym=-1,ch=__getc();
			for(;ch>='0'&&ch<='9';x*=10,x+=(ch^48),ch=__getc());
			return x*=sym,*this;
		}
		inline FastInput &operator >>(char *s)
		{
			while((*s=__getc())<33);
			for(;*s>32;*(++s)=__getc());
			return *s='\0',*this;
		}
		inline FastInput &operator >>(string &s)
		{
			char *p=str_buf;
			while((*p=__getc())<33);for(;*p>32;*(++p)=__getc());
			*p='\0',s=str_buf;
			return *this;
		}
		template<typename ...T>
		inline void read(T &...x)
			{ int var[]={(this->operator>>(x),0)...}; }
	}qin;
	char FastInput::str_buf[1<<22]="";
}
using namespace FastIO;
typedef long long LL;
int n,s,q,ans,MOD;
inline LL quickPow(LL a,LL b,int mod=MOD)
{
	LL res=1;
	for(;b;a=a*a%mod,b>>=1)if(b&1)res=res*a%mod;
	return res;
}
inline int madd(int x,int y)	{ return (x+=y)>=MOD?(x-=MOD):x; }
inline int msub(int x,int y)	{ return (x-=y)<0?(x+=MOD):x; }
inline int mmul(int x,int y)	{ return (LL)x*y%MOD; }
inline int mdiv(int x,int y)	{ return (LL)x*quickPow(y,MOD-2)%MOD; }
int lim,tmp,fac[2000005],inv[2000005];
int main()
{
	qin>>n>>s>>q,MOD=q,lim=n+q;
	fac[0]=1;
	for(int i=1;i<=lim;i++)	fac[i]=mmul(fac[i-1],i);
	inv[lim]=quickPow(fac[lim],MOD-2);
	for(int i=lim;i>=1;i--)	inv[i-1]=mmul(inv[i],i);
	tmp=msub(quickPow(2,q),1);
	for(int i=0;i<n;i++)
		if(((LL)i*q+quickPow(i,q,n))%n==s)
			ans=madd(ans,madd(mmul(fac[q+i],inv[i]),mmul(tmp,i)));
	qout<<ans;
//	return qout.flush(),0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3460kb

input:

2 0 2

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 3ms
memory: 3544kb

input:

10 9 2

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 3ms
memory: 3540kb

input:

3 2 3

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3580kb

input:

2 1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

4 0 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 3ms
memory: 3604kb

input:

4 2 3

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 3ms
memory: 3604kb

input:

20 4 19

output:

5

result:

ok 1 number(s): "5"

Test #8:

score: 0
Accepted
time: 3ms
memory: 3600kb

input:

30 2 37

output:

23

result:

ok 1 number(s): "23"

Test #9:

score: 0
Accepted
time: 3ms
memory: 3680kb

input:

87 22 67

output:

0

result:

ok 1 number(s): "0"

Test #10:

score: 0
Accepted
time: 3ms
memory: 3672kb

input:

829 135 857

output:

803

result:

ok 1 number(s): "803"

Test #11:

score: 0
Accepted
time: 4ms
memory: 3700kb

input:

6120 2790 9851

output:

4622

result:

ok 1 number(s): "4622"

Test #12:

score: 0
Accepted
time: 22ms
memory: 4524kb

input:

77263 13087 50147

output:

26904

result:

ok 1 number(s): "26904"

Test #13:

score: 0
Accepted
time: 244ms
memory: 13920kb

input:

682298 437284 638801

output:

10038

result:

ok 1 number(s): "10038"

Test #14:

score: 0
Accepted
time: 286ms
memory: 14508kb

input:

823965 703789 575623

output:

483248

result:

ok 1 number(s): "483248"

Test #15:

score: 0
Accepted
time: 363ms
memory: 19192kb

input:

1000000 394496 999983

output:

755554

result:

ok 1 number(s): "755554"

Test #16:

score: 0
Accepted
time: 357ms
memory: 19160kb

input:

1000000 24900 999451

output:

996185

result:

ok 1 number(s): "996185"

Test #17:

score: 0
Accepted
time: 371ms
memory: 19304kb

input:

999750 14190 999671

output:

191073

result:

ok 1 number(s): "191073"

Test #18:

score: 0
Accepted
time: 352ms
memory: 18752kb

input:

946312 10286 997741

output:

744939

result:

ok 1 number(s): "744939"

Test #19:

score: 0
Accepted
time: 372ms
memory: 19312kb

input:

997742 0 997741

output:

565729

result:

ok 1 number(s): "565729"

Test #20:

score: 0
Accepted
time: 367ms
memory: 18804kb

input:

977762 0 977761

output:

0

result:

ok 1 number(s): "0"