fork(3) download
  1. #include<bits/stdc++.h>
  2. #define FOR(i,a,b,k) for (ll i=a;i<=b;i+=k)
  3. #define FORD(i,a,b,k) for (ll i=a;i>=b;i-=k)
  4. #define pb(i) push_back(i)
  5. #define ll long long int
  6. #define MOD 1e9+7
  7. #define all(a) (a).begin(), (a).end()
  8. #define fi first
  9. #define se second
  10. #define hay_goi_minh_la_long_xau_trai_hoc_dot_hay_chep_bai_ban_di ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  11. #define hay_goi_minh_la_long_dep_trai_di_vi_minh_xau_trai_vai_beep() int main()
  12. using namespace std;
  13.  
  14. template<typename T> ll power(T &a, const T &b) { ll res = 1, x = a, y = b; while(y){if(y & 1)res *= x; x = x * x; y>>=1;}; return res; }
  15. template<typename T> ll modpower(T &a, const T &b, const T &m) { ll res = 1, x = a, y = b; x %= m; while(y){if(y & 1)res *= x % m; x = x * x % m; y>>=1; }; return res; }
  16.  
  17. inline ll readll() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
  18. inline string readstring() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}
  19.  
  20. // het phan lon xao roi, gio moi vao code chinh
  21. ll t,a,b,n; // bien xu ly nhap
  22. ll lcd,mid; // bien xu ly chat nhi phan
  23. ll T,dem; // bien cho xu ly chu ky toan
  24.  
  25. bool kt(ll x)
  26. {
  27. if(x/a+x/b-x/lcd<n) return 0;
  28. return 1;
  29. }
  30.  
  31. void loading()
  32. {
  33. ll l=dem*lcd,r=(dem+1)*lcd;
  34. while(l<r)
  35. {
  36. mid=(l+r)/2;
  37. if(!kt(mid)) l=mid+1; else r=mid;
  38. }
  39. cout<<l<<'\n';
  40. }
  41.  
  42.  
  43. hay_goi_minh_la_long_dep_trai_di_vi_minh_xau_trai_vai_beep()
  44. {
  45. hay_goi_minh_la_long_xau_trai_hoc_dot_hay_chep_bai_ban_di
  46. t=readll();
  47. while(t--)
  48. {
  49. a=readll();
  50. b=readll();
  51. n=readll();
  52.  
  53. lcd=a*b/__gcd(a,b);
  54. T=lcd/a+lcd/b-1;
  55. dem=n/T;
  56.  
  57. loading();
  58. }
  59.  
  60. return 0;
  61. }
Time limit exceeded #stdin #stdout 5s 5612KB
stdin
Standard input is empty
stdout
Standard output is empty