QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21613#2845. 密码学第三次小作业gsh#AC ✓38ms3648kbC++202.3kb2022-03-07 16:39:282022-05-08 03:42:58

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-08 03:42:58]
  • 评测
  • 测评结果:AC
  • 用时:38ms
  • 内存:3648kb
  • [2022-03-07 16:39:28]
  • 提交

answer

#include<map>
#include<set>
#include<queue>
#include<deque>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
#define mkp make_pair
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define fs fflush(stdout)
#define ump unordered_map
#define pq priority_queue
#define clz __builtin_clz
#define ctz __builtin_ctz
#define space putchar(' ')
#define enter putchar('\n')
#define sz(x) (int)x.size()
#define np next_permutation
#define clzl __builtin_clzll
#define par __builtin_parity
#define ctzl __builtin_ctzll
#define ppc __builtin_popcount
#define parl __builtin_parityll
#define all(x) x.begin(),x.end()
#define ppcl __builtin_popcountll
#define ms(x,y) memset(x,y,sizeof(x))
#define debug(x) cerr<<#x<<"= "<<(x)<<'\n'
template<class T> inline T &read(T &x){
	x=0;int f=1;char ch=getchar();
	while(ch<48||ch>57){if(ch=='-') f=-f;ch=getchar();}
	while(ch>=48&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x*=f;
}
template<class T> inline void print(T x){
	static char buf[40];static int cnt=0;
	if(x<0) putchar(45),x=-x;
	do buf[++cnt]=x%10^48;while(x/=10);
	do putchar(buf[cnt--]);while(cnt);
}
#define mod 998244353
#define inf 0x3f3f3f3f
#define fpi freopen("","r",stdin)
#define fpo freopen("","w",stdout)
ll n;
void exgcd(__int128 a,__int128 b,__int128 &x,__int128 &y){
	if(!b){x=1,y=0;return ;}
	exgcd(b,a%b,x,y);
	__int128 z=x;x=y,y=z-a/b*y;
}
inline ll lmod(ll x){return x+(x>>63&n);}
inline __int128 ksm(__int128 cur,__int128 indx){
	__int128 res=1;
	while(indx){
		if(indx&1) (res*=cur)%=n;
		(cur*=cur)%=n,indx>>=1;
	}return res;
}
void solve(){
	__int128 c1=read(c1),c2=read(c2),e1=read(e1),e2=read(e2),x,y,xx,xxx,yy,ans=1;read(n);
	exgcd(e1,e2,x,y),exgcd(c1,n,xx,yy),xx=lmod(xx%n),exgcd(c2,n,xxx,yy),xxx=lmod(xxx%n);
	if(x<0) (ans*=ksm(xx,-x))%=n;else (ans*=ksm(c1,x))%=n;
	if(y<0) (ans*=ksm(xxx,-y))%=n;else (ans*=ksm(c2,y))%=n;
	print(ans),enter;
	return ;
}
int main(){
	int t=read(t);while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 16ms
memory: 3604kb

input:

10000
194765009 590879477 22481 11801 596329817
437621144 509036484 18587 3203 820537651
645177263 749030649 5821 13931 905781727
246944928 634474710 467 23371 726675529
605059247 536773554 21499 11519 733241959
53572985 261038149 23209 1303 679323269
314446191 738402036 12973 28961 825774259
359483...

output:

3745484
95327130
296809360
260917393
5910400
215017122
209461189
9944422
328546137
422624753
134605625
460020274
532874246
515467840
414967122
584661331
575708794
455212601
34579391
300543756
297635435
829111593
257490797
377499646
339663690
530810590
430294196
279963294
314834816
346080261
43793086...

result:

ok  (10000 test cases)

Test #2:

score: 0
Accepted
time: 38ms
memory: 3648kb

input:

10000
421334545191079239 447565396010357899 607319 686761 555388527903369997
482840423399033737 434258320005377506 168083 52711 699821164707511453
342876142292626109 418004883829192067 466201 672913 706900388919931487
239546138630487720 2083287231715587034 879247 532417 2580420336112804147
218169150...

output:

455273291313157504
46398738587396768
72660497104269680
988613982675111040
587199639602402688
481927093525894400
142105005862797856
178522718341774624
145106382430967040
197414524611321696
1659534362403244032
3922428012540531
1129237605899348736
416304549016197248
234913278456251680
15138153767239190...

result:

ok  (10000 test cases)