1 条题解
-
1Root (sky1231) LV 8 MOD @ 2018-05-14 12:07:45
#include <cmath> #include <ctime> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <vector> #include <deque> #include <set> #include <limits> #include <string> #include <sstream> using namespace std; namespace dts { typedef long long ll; ll n,m,t,key; ll qp(ll x,ll y,ll key) { ll ans=1; for (ll i=x,j=y;j>0;i=(i*i)%key,j/=2) if (j&1) ans=(ans*i)%key; return ans; } ll ny(ll x,ll key) { if (x==1) return 1; else return -(key/x)*ny(key%x,key)%key; } void main() { while (~scanf("%lld%lld%lld%lld",&n,&m,&t,&key)) { m%=key; ll p=ny(m,key); if (p<0) p+=((key-p)/key)*key; ll f=qp(m-1,n,key)+(m-1)*((n&1)?-1:1),g=(m-1)*qp(m-1,n,key)+(1-m)*((n&1)?-1:1); if (f<0) f+=((key-f)/key)*key; if (g<0) g+=((key-g)/key)*key; f=((f%key)*p)%key,g=((g%key)*p)%key; //f(x)=(m-1)^x/m+(m-1)*(-1)^x/m //g(x)=(m-1)*(m-1)^x/m+(1-m)*(-1)^x/m t%=key; printf("%lld %lld\n",(f*t)%key,(g*t)%key); } } }; int main() { dts::main(); }
- 1