QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#745451#9622. 有限小数yhdddWA 0ms3804kbC++141.3kb2024-11-14 10:02:322024-11-14 10:02:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 10:02:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3804kb
  • [2024-11-14 10:02:32]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e9;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int a,b;
pii ans={inf,inf};
void exgcd(int a,int b,int &x,int &y){
	if(!b){
		x=1,y=0;
		return ;
	}
	exgcd(b,a%b,x,y);
	int p=x;
	x=y,y=p-(a/b)*y;
}
void work(){
	a=read(),b=read();ans={inf,inf};
	int p=1;
	while(b%2==0)b/=2,p*=2;
	while(b%5==0)b/=5,p*=5;
	if(b==1){puts("0 1");return ;}
	for(int i=1;i*b<=inf;i*=2){
		for(int j=i;j*b<=inf;j*=5){
			int q=j;
			int xx=0,yy=0;
			exgcd(b,-p,xx,yy);
			xx*=a*q,yy*=a*q;
			// cout<<xx<<" "<<yy<<" "<<p<<" "<<b<<"\n";
			int c=yy,d=q*b;
			c%=b,c+=b,c%=b;
			ans=min(ans,{c,q*b});
		}
	}
	printf("%lld %lld\n",ans.fi,ans.se);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=read();
	while(T--)work();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3804kb

input:

4
1 2
2 3
3 7
19 79

output:

0 1
1 6
1 35
1 1975

result:

wrong answer The result is not terminating.(Testcase 2)