background:
Today, I have found fast ride
approach.
Topic:
The solution is to ride fast
issues.
sometimes
particularly large,
:
principle:
written recursive or recursive form, in which each position can be
can be.
note:
results from the symbol
determination, therefore
result from the symbol
OK.
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
LL x,y,mod;
LL dg(LL x,LL y,LL mod)
{
if(y==1) return x;
LL op=dg(x,y>>1,mod);
if(y&1) return (op*2%mod+x)%mod; else return op*2%mod;
}
int main()
{
scanf("%lld %lld %lld",&x,&y,&mod);
int op=((x<0&&y>0)||(x>0&&y<0));
printf("%lld\n",(op?-1ll:1ll)*dg(abs(x),abs(y),abs(mod)));
}
:
principle:
At this point, our process with the amount
to store can be.
note:
results from the symbol
determination, therefore
result from the symbol
OK.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef long double LD;
LL x,y,mod;
LL times(LL x,LL y,LL mod)
{
LD t=LD(x)*LD(y)-LL(LD(x)*LD(y)/LD(mod))*LD(mod);
LL tt=(LL)t;
return tt>=0?tt%mod:(tt+mod)%mod;
}
int main()
{
scanf("%lld %lld %lld",&x,&y,&mod);
int op=((x<0&&y>0)||(x>0&&y<0));
printf("%lld\n",(op?-1ll:1ll)*times(abs(x),abs(y),abs(mod)));
}