Codeforces 1088A - Ehab and another construction problem

in 题解 with 0 comment

Codeforces 1088A - Ehab and another construction problem

题解链接

https://lucien.ink


题目链接

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


题目

Given an integer $x$, find 2 integers $a$ and $b$ such that:


题意

  给你一个$x$,让你找一对$a$、$b$,使得$a$、$b$满足上述条件。


思路

  显然$x$等于$1$的时候无解,故特判掉,之后虽然可以观察出来解,但还是证明一下吧。

  令:$a = k \cdot b\ (k \in Z)$

  则有:$k \cdot b \cdot b > x$、$k < x$同时成立。

  不妨设:$k = 1$,则有:$b ^ 2 > x$,此时$a = b$,

  即:取$a = b = x$即可。


实现

https://pasteme.cn/2207

#include <bits/stdc++.h>
typedef long long ll;
int main() {
    ll x;
    std::cin >> x;
    if (x == 1) puts("-1");
    else printf("%lld %lld\n", x, x);
    return 0;
}
Responses