ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213256 | #3847. 分数约分 | 18112606231 | 0 | 2546ms | 1276kb | C++11 | 1.7kb | 2024-11-10 09:39:53 | 2024-11-10 13:03:57 |
answer
#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int t,a,b,n,gcdd,minn,minx;
string s,ss;
bool xuan[21];
int stolll(string s)
{
int res=0;
for(int i=0;i<s.size();i++)
{
res=res*10+s[i]-'0';
}
return res;
}
void dfs(int x)
{
if(x==n)
{
string res="";
for(int i=0;i<n;i++)
{
if(xuan[i])
{
res+=s[i];
}
}
int num=stolll(res);
if(num==0)
return;
if(a*b%num!=0)
return;
num=b*num/a;
string res2=to_string(num);
string res3="";
for(int i=0,j=0;i<res2.size(),j<ss.size();j++)
{
if(res2[i]==ss[j])
{
res3+=ss[j];
i++;
}
}
//cout<<res<<' '<<res2<<' '<<res3<<' '<<gcdd<<endl;
if(res3==res2)
{
int ans1=stolll(res);
int ans2=stolll(res3);
minn=min(minn,ans1);
minx=min(minx,ans2);
}
return;
}
xuan[x]=true;
dfs(x+1);
xuan[x]=false;
dfs(x+1);
}
signed main()
{
scanf("%lld",&t);
while(t--)
{
scanf("%lld %lld",&a,&b);
memset(xuan,0,sizeof(xuan));
bool flag=false;
if(a>b)
{
flag=true;
swap(a,b);
}minn=a,minx=b;
s=to_string(a);
ss=to_string(b);
n=s.size();
dfs(0);
if(!flag)
printf("%lld %lld\n",minn,minx);
else
printf("%lld %lld\n",minx,minn);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
10 295227892 738069730 21284157 63852471 312774536 781936340 82221828 68518190 167752458 55917486 90...
output:
295227892 738069730 1 3 4 10 1 1 12 4 4 32 1 7 1 1 1 3 1 1
result:
wrong answer 3rd numbers differ - expected: '21', found: '1'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
10 7231248 1807812 4301415 3441132 1931046 3862092 5184264 3240165 1144774 1717161 298584 2388672 87...
output:
4 1 1 1 1 2 1 1 1 1 4 32 1 9 8 64 1 1 2 5
result:
wrong answer 1st numbers differ - expected: '324', found: '4'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1268kb
input:
10 72320000 27120000 110000 11000000 90100000 9010000 270000 75600000 8230000 82300000 17910000 5970...
output:
2 1 1 100 10 1 2 560 2 20 1791 597 893 94 60 6 7 70 4634 6620
result:
wrong answer 1st numbers differ - expected: '32', found: '2'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1268kb
input:
10 6700512 10050768 6712050 10068075 7172058 10758087 9318720 13978080 71635224 107452836 71643522 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer 1st numbers differ - expected: '670512', found: '1'
Test #5:
score: 0
Wrong Answer
time: 531ms
memory: 1276kb
input:
10 44896548685746979 44896548685746979 76555658957975878 76555658957975878 9999998899899899 99999988...
output:
44896548685746979 44896548685746979 5 5 9 9 66866776659978777 66866776659978777 2 2 9 9 989898888898...
result:
wrong answer 1st numbers differ - expected: '4', found: '44896548685746979'
Test #6:
score: 0
Wrong Answer
time: 292ms
memory: 1272kb
input:
10 5586978859946748 5586978859946748 5875932326322532 5875932326322532 7877997999879887 787799799987...
output:
4 4 2 2 97 97 99999999999999999 99999999999999999 4 4 8 8 8 8 8689979595794777 8689979595794777 7777...
result:
wrong answer 5th numbers differ - expected: '7', found: '97'
Test #7:
score: 0
Wrong Answer
time: 248ms
memory: 1272kb
input:
10 163163163163163 326326326326326 163163111163111 326326222326222 142847142847 285714285714 2857142...
output:
1 2 1 2 1 2 1 2 2 1 11 1 26 2 9 1 443191930710990010 19660082200466607 22 1
result:
wrong answer 1st numbers differ - expected: '11111', found: '1'
Test #8:
score: 0
Time Limit Exceeded
input:
10 142847114287112857 285714228574225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
result:
Test #9:
score: 0
Wrong Answer
time: 548ms
memory: 1272kb
input:
10 687069149440626451 336182506802090732 216198376277246428 246457923661369649 43706817238884428 372...
output:
2 1 1 1 1 8 2 2 177216199700930599 99466809602520377 1 2 1 2 1 2 1 25 2 1
result:
wrong answer 1st numbers differ - expected: '687069149440626451', found: '2'
Test #10:
score: 0
Wrong Answer
time: 927ms
memory: 1276kb
input:
10 142847114247112857 285714228714225714 142847111111112857 285714222222225714 142847111111111111 28...
output:
1 2 1 2 1 2 1 2 1 2 1 1 1 9 1 115 33122675989772288 686915733077099457 1 1
result:
wrong answer 1st numbers differ - expected: '142847114247112857', found: '1'