建议加强数据
查看原帖
建议加强数据
774658
skyc13楼主2025/8/29 22:14

这样做就过了?O(logb) 提交记录

#include<bits/stdc++.h>
typedef long long LL;
#ifdef WIN32
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#else
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
using namespace std;
namespace fastIO
{
	inline char get_char()
	{
		char c=getchar();
		for(;c<=32&&c!=EOF;c=getchar());
		return c;
	}
	inline int read()
	{
		int x=0,f=1;
		char c=getchar();
		for(;c<'0'||c>'9';c=getchar()){if(c=='-') f=-1;if(c==EOF) return c;}
		for(;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+c-48;
		return x*f;
	}
	inline void write(int x)
	{
		if(x<0) putchar('-'),x=-x;
		if(x>9) write(x/10);
		putchar(x%10+48);
	}
	inline void file()
	{
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	}
	inline void close()
	{
		fclose(stdin);
		fclose(stdout);
	}
	inline void fast()
	{
		ios::sync_with_stdio(false);
		cin.tie(NULL);
		cout.tie(NULL);
	}
}
using namespace fastIO;
namespace my
{
	const int N=2e7+1,count=6,ten=1e6;
	int a,m,pow[ten];
	char b[N];
	inline int fastpow(LL a,int b)
	{
		int ans=1;
		while(b){
			if(b&1) ans=ans*a%m;
			a=a*a%m;
			b>>=1;
		}
		return ans;
	}
	int main()
	{
		a=read();m=read();
		a%=m;
		if(m==1||a==0){
			putchar('0');
			return 0;
		}
		int lenb=0;
		for(char ch=get_char();ch!=EOF;ch=get_char()) b[++lenb]=ch;
		pow[0]=1;
		for(int i=1;i<ten;++i) pow[i]=(LL)pow[i-1]*a%m;
		int ans=1;
		for(int i=1;i+count-1<=lenb&&ans;i+=count){
			int x=0;
			for(int j=i;j<i+count;++j) x=(x<<3)+(x<<1)+b[j]-48;
			ans=(LL)fastpow(ans,ten)*pow[x]%m;
		}
		for(int i=lenb/count*count+1;i<=lenb&&ans;++i) ans=(LL)fastpow(ans,10)*pow[b[i]-48]%m;
		write(ans);
		return 0;
	}
}
int main()
{
	my::main();
	return 0;
}
2025/8/29 22:14
加载中...