문제 출처 : https://www.acmicpc.net/problem/6064

<C++code>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
using namespace std;
int main(void){
    int c;
    cin>>c;
    while(c--)
    {
        int n,m,x,y;
        cin>>n>>m>>x>>y;
        x-=1;
        y-=1;
        bool find=false;
        for(int i=x;i<(n*m);i+=n)
        {
            if(i%m==y)
            {
                cout<<i+1<<endl;
                find=true;
                break;
            }
        }
        if(!find)
        {
            cout<<-1<<endl;
        }
    }
    
    return 0;
    
}
cs

'백준 온라인 저지 > 브루트 포스2' 카테고리의 다른 글

1107번_리모컨  (0) 2020.01.05
3085번_사탕 게임  (0) 2020.01.05
2309번_일곱난쟁이  (0) 2020.01.03

+ Recent posts