結果

問題 No.1287 えぬけー
ユーザー furafura
提出日時 2020-11-15 19:00:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,192 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 205,584 KB
実行使用メモリ 15,392 KB
最終ジャッジ日時 2023-09-30 07:04:54
合計ジャッジ時間 6,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 123 ms
10,764 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

lint modinv(lint a,lint m){
	lint b=m,u=1,v=0;
	while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
	return (u+m)%m;
}

lint modpow(lint a,lint k,int m){
	lint r=1%m;
	for(lint x=a%m;k>0;k>>=1,x=x*x%m) if(k&1) r=r*x%m;
	return r;
}

int modlog(lint a,lint b,int p){
	a%=p; if(a<0) a+=p;
	b%=p; if(b<0) b+=p;

/*
	int k=sqrt(p)+1,c=1;
	vector<pair<int,int>> H(k);
	rep(j,k) H[j]={c,j}, c=c*a%p;
	sort(H.begin(),H.end());
*/
// BSGS の前半は一度だけ計算
	static int k=1e6,c=1;
	static vector<pair<int,int>> H(k);
	static bool first=true;
	if(first){
		first=false;
		rep(j,k) H[j]={c,j}, c=c*a%p;
		sort(H.begin(),H.end());
	}

	c=modinv(c,p);
	rep(i,k){
		auto it=lower_bound(H.begin(),H.end(),make_pair(int(b),0));
		if(it!=H.end() && it->first==b) return i*k+(it->second);
		b=b*c%p;
	}
	return -1;
}

void solve(){
	lint p=1e9+7;
	lint x,k; scanf("%lld%lld",&x,&k);

	if(x==0){
		puts("0");
		return;
	}

//	lint g=gcd(k,p-1);
	printf("%lld\n",modpow(5,modlog(5,x,p)*modinv(k,p-1),p)%p);
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0