Submission #48268912
Source Code Expand
// LUOGU_RID: 138675894
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)
#ifdef EXODUS
#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define Debug(...) 0
#endif
//=========================================================================================================
// Something about IO
template<typename T>
void read(T &x){
x=0;T flg=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}
//=========================================================================================================
// Define the global variables here.
bool membg=0;
ll a,b,ans;
bool memed=0;
//=========================================================================================================
// Code here.
void solve(ll v){
ll res=b;
auto fix=[&](ll x){if(a%x==b%x)res=min(res,a%x);};
for(ll i=2;i*i<=v;i++)if(v%i==0)fix(i),fix(v/i);fix(v);
a-=res,b-=res,ans+=res;return;
}
void solve(){
read(a,b);
while(a&&b){
// Debug("%lld %lld\n",a,b);
if(a<b)swap(a,b);
ll g=__gcd(a,b);
a/=g,b/=g;
if(a==b){ans++;break;}
if(a==b+1){ans+=b;break;}
solve(a-b);
}
printf("%lld\n",ans);
return;
}
//=========================================================================================================
int main(){
Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
int timbg=clock();
int T=1;
while(T--)solve();
int timed=clock();
Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
fflush(stdout);
return 0;
}
Submission Info
Submission Time
2023-12-08 17:29:15+0900
Task
B - GCD Subtraction
User
EXODUS
Language
C++ 17 (gcc 12.2)
Score
400
Code Size
2012 Byte
Status
AC
Exec Time
4 ms
Memory
3932 KiB
Compile Error
Main.cpp: In function ‘void solve(ll)’:
Main.cpp:50:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
50 | for(ll i=2;i*i<=v;i++)if(v%i==0)fix(i),fix(v/i);fix(v);
| ^~~
Main.cpp:50:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
50 | for(ll i=2;i*i<=v;i++)if(v%i==0)fix(i),fix(v/i);fix(v);
| ^~~
Main.cpp: In function ‘int main()’:
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
18 | #define Debug(...) 0
| ^
Main.cpp:73:9: note: in expansion of macro ‘Debug’
73 | Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
| ^~~~~
Main.cpp:18:28: warning: statement has no effect [-Wunused-value]
18 | #define Debug(...) 0
| ^
Main.cpp:78:9: note: in expansion of macro ‘Debug’
78 | Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
| ^~~~~
Main.cpp:74:13: warning: unused variable ‘timbg’ [-Wunused-variable]
74 | int timbg=clock();
| ^~~~~
Main.cpp:77:13: warning: unused variable ‘timed’ [-Wunused-variable]
77 | int timed=clock();
| ^~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
400 / 400
Status
Set Name
Test Cases
Sample
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 02_same_00.txt, 02_same_01.txt, 02_same_02.txt, 02_same_03.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 04_max2_00.txt, 04_max2_01.txt, 04_max2_02.txt, 04_max2_03.txt, 04_max2_04.txt, 04_max2_05.txt, 04_max2_06.txt, 04_max2_07.txt, 04_max2_08.txt, 04_max2_09.txt, 05_max3_00.txt, 05_max3_01.txt, 05_max3_02.txt, 05_max3_03.txt, 05_max3_04.txt, 05_max3_05.txt, 05_max3_06.txt, 05_max3_07.txt, 05_max3_08.txt, 05_max3_09.txt, 05_max3_10.txt
Case Name
Status
Exec Time
Memory
00_sample_00.txt
AC
1 ms
3924 KiB
00_sample_01.txt
AC
1 ms
3720 KiB
00_sample_02.txt
AC
1 ms
3752 KiB
01_rnd_00.txt
AC
1 ms
3756 KiB
01_rnd_01.txt
AC
2 ms
3752 KiB
01_rnd_02.txt
AC
2 ms
3868 KiB
01_rnd_03.txt
AC
2 ms
3864 KiB
01_rnd_04.txt
AC
3 ms
3732 KiB
01_rnd_05.txt
AC
1 ms
3720 KiB
01_rnd_06.txt
AC
2 ms
3812 KiB
01_rnd_07.txt
AC
4 ms
3704 KiB
01_rnd_08.txt
AC
1 ms
3868 KiB
01_rnd_09.txt
AC
1 ms
3740 KiB
02_same_00.txt
AC
1 ms
3932 KiB
02_same_01.txt
AC
1 ms
3708 KiB
02_same_02.txt
AC
1 ms
3860 KiB
02_same_03.txt
AC
1 ms
3752 KiB
03_max_00.txt
AC
1 ms
3932 KiB
03_max_01.txt
AC
1 ms
3812 KiB
03_max_02.txt
AC
1 ms
3812 KiB
04_max2_00.txt
AC
1 ms
3864 KiB
04_max2_01.txt
AC
1 ms
3708 KiB
04_max2_02.txt
AC
1 ms
3816 KiB
04_max2_03.txt
AC
1 ms
3732 KiB
04_max2_04.txt
AC
1 ms
3872 KiB
04_max2_05.txt
AC
1 ms
3872 KiB
04_max2_06.txt
AC
1 ms
3896 KiB
04_max2_07.txt
AC
1 ms
3656 KiB
04_max2_08.txt
AC
2 ms
3756 KiB
04_max2_09.txt
AC
2 ms
3760 KiB
05_max3_00.txt
AC
1 ms
3748 KiB
05_max3_01.txt
AC
1 ms
3736 KiB
05_max3_02.txt
AC
1 ms
3876 KiB
05_max3_03.txt
AC
1 ms
3668 KiB
05_max3_04.txt
AC
1 ms
3752 KiB
05_max3_05.txt
AC
1 ms
3796 KiB
05_max3_06.txt
AC
1 ms
3856 KiB
05_max3_07.txt
AC
1 ms
3752 KiB
05_max3_08.txt
AC
1 ms
3932 KiB
05_max3_09.txt
AC
1 ms
3832 KiB
05_max3_10.txt
AC
1 ms
3708 KiB