# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1073320 | beaconmc | Pictionary (COCI18_pictionary) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i++)
using namespace std;
int main(){
ll n,m,q;
cin >> n >> m >> q;
FOR(i,0,q){
ll ans = m;
ll a,b;
cin >> a >> b;
vector<ll> as, bs;
FOR(i,1,sqrt(a)+2){
if (a%i==0){
as.push_back(i);
as.push_back(a/i);
}
}
FOR(i,1,sqrt(b)+2){
if (b%i==0){
bs.push_back(i);
bs.push_back(b/i);
}
}
for (auto&A : as){
for (auto&B : bs){
if (lcm(A,B) <= n && 0<=m-min(A,B)){
ans = min(ans, m-min(A,B));
}
}
}
cout << ans+1 << "\n";
}
}