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

it2022-05-05  124

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

题目连接

题意

已知:

已知一个x(1<=x<=100)

求解: 求两个数a和b,使a和b满足以下限制条件。 如果找不到这样的整数就输出“-1”。

思路:

水题,直接两个循环暴力就能过。

AC代码:

#include <bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; for(int i=1;i<=x;i++){ for(int j=1;j<=i;j++){ if(i%j==0){ if(i*j>x && i/j<x){ printf("%d %d",i,j); return 0; } } } } cout<<"-1"; return 0; }

看到其他博客上还有更简洁的方法,但是不明白是为什么…


最新回复(0)