QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402514#6440. Xingqiu's JokeyhdddWA 660ms24632kbC++141.2kb2024-04-30 18:53:142024-04-30 18:53:15

Judging History

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

  • [2024-04-30 18:53:15]
  • 评测
  • 测评结果:WA
  • 用时:660ms
  • 内存:24632kb
  • [2024-04-30 18:53:14]
  • 提交

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))
using namespace std;
const int maxn=200010;
const int inf=1e18;
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,c;
vector<int> p;
map<pii,int> dp;
int dfs(int a,int c){
	if(dp[{a,c}])return dp[{a,c}];
	if(a==1)return 0;
	int ans=a-1;
	for(int i:p)if(c%i==0){
		ans=min({ans,a%i+1+dfs(a/i,c/i),(i-a%i)%i+1+dfs(a/i+1,c/i)});
	}
//	cout<<a<<" "<<c<<" "<<ans<<"\n";
	return dp[{a,c}]=ans;
}
void work(){
	a=read();b=read();p.clear();
	if(a>b)swap(a,b);
	c=b-a;int x=c;
	for(int i=2;i*i<=x;i++)if(x%i==0){
		p.push_back(i);
		while(x%i==0)x/=i;
	}
	if(x>1)p.push_back(x);
	printf("%lld\n",dfs(a,c));
}

// \
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();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3824kb

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
7
5
4
0

result:

ok 5 number(s): "2 7 5 4 0"

Test #2:

score: -100
Wrong Answer
time: 660ms
memory: 24632kb

input:

300
223528529 446621399
755625805 978718675
257717538 480810408
277875777 54782907
963091558 739998688
282469431 505562301
38752451 261845321
474429597 697522467
67026335 290119205
874629705 651536835
301964126 78871256
316864911 93772041
545942587 322849717
640801578 417708708
683070559 906163429
9...

output:

10
16
12
13
15
15
11
15
14
13
11
11
15
13
14
16
12
15
12
15
16
16
14
13
14
14
14
11
18
11
10
16
12
13
10
13
14
16
13
13
13
15
11
12
11
12
16
14
15
13
13
15
13
16
11
13
14
11
13
14
13
16
16
15
14
12
13
13
21
11
10
11
16
18
10
12
15
15
9
14
14
15
12
14
14
11
14
12
14
15
14
10
14
15
14
13
14
11
12
13
1...

result:

wrong answer 1st numbers differ - expected: '12', found: '10'