สมมติว่าเรามีจำนวน x เราต้องหาจำนวนเต็ม a และ b สองตัว โดยที่ทั้งคู่จะอยู่ระหว่าง 1 ถึง x a หารด้วย b ลงตัว a * b> x แต่ a/b
เพื่อแก้ปัญหานี้ เราจะทำตามขั้นตอนเหล่านี้ -
if x < 2, then: print -1 return print x and x
ตัวอย่าง
ให้เราดูการใช้งานต่อไปนี้เพื่อความเข้าใจที่ดีขึ้น -
#include <bits/stdc++.h> using namespace std; void solve(int x){ if (x < 2){ cout << -1; return; } cout << x << ", " << x; } int main(){ int x = 10; solve(x); }
อินพุต
10
ผลลัพธ์
10,10