fork download
  1. #include <bits/stdc++.h>
  2. #define pii pair<int,int>
  3. #define fi first
  4. #define int long long
  5. #define se second
  6. #define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  7. #define op freopen
  8. #define TXT "test"
  9. #define freo if(fopen(TXT".inp","r")){op(TXT".inp","r",stdin);op(TXT".out","w",stdout);}
  10.  
  11. using namespace std;
  12. int t,a,b,k,lcm;
  13. int so(int m)
  14. {
  15. return m-(m/a+m/b-m/lcm);
  16. }
  17. void bs(int l,int r)
  18. {
  19. int m,ans;
  20. while(l<=r)
  21. {
  22. m=(l+r)>>1;
  23. if(so(m)<k)
  24. {
  25. ans=m;
  26. l=m+1;
  27. }
  28. else
  29. {
  30. r=m-1;
  31. }
  32. }
  33. cout<<ans+1<<"\n";
  34. }
  35. main()
  36. {
  37. ios;
  38. freo;
  39. cin>>t;
  40. while(t--)
  41. {
  42. cin>>k>>a>>b;
  43. lcm=a/__gcd(a,b)*b;
  44. bs(1,k*max(a,b));
  45. }
  46. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty