Competition/codeforces

Codeforces Round #525 (Div. 2) A. Ehab and another construction problem

shyram 2019. 3. 29. 01:27

A. Ehab and another construction problem

https://codeforces.com/problemset/problem/1088/A


모든 경우를 전부 탐색하면 된다.

1부터 탐색하여 i의 배수를 찾았으면, 그게 a=i 일때의 최대값이다.

a*b>n 조건에 의해 최대 값만 확인하면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;
 
int n, a, b;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = n; j >= i; j--) {
            if (j%i == 0) {
                if (i*> n && j / i < n) {
                    cout << j << ' ' << i;
                    exit(0);
                }
                break;
            }
        }
    }
    cout << -1;
    return 0;
}
cs