【CodeChef】Just multiply
数据水
讲道理,指数循环节不能直接取模
#include<bits/stdc++.h>
using namespace std;
char inc;
inline void get(int& x)
{
x = 0;inc = getchar();
while(!isdigit(inc))inc=getchar();
while(isdigit(inc))
{
x=x*10+inc-'0';
inc=getchar();
}
}
#define maxn 10010
int T,mod,len;typedef long long ll;
char s[maxn];
ll mul(ll x,ll p)
{
if(x==0)return 0;
if(p==0)return 1;
ll t = x,ret=1;
while(p)
{
if(p&1)ret*=t;
t*=t;
t%=mod;
ret%=mod;
p>>=1;
}
return ret;
}
int main()
{
get(T);
while(T--)
{
get(mod);scanf("%s",s);
len = strlen(s);
ll last = 1;bool flag = false;
ll fir = 0,sec = 0;
for(int i=0;i<len;i++)
{
if(s[i]!='*')
{
if(!flag)fir = (fir*10+s[i]-'0')%mod;
else sec = (sec*10+s[i]-'0')%mod;
}
else
{