r = max{2na, 2},(其中n为正整数)。
#include <iostream>
using namespace std;
int main() {
int num{}, a{};
cin >> num;
for (int i{}; i < num && cin >> a; i++) {
int k{ 2 };
while (k * a < a * a) k += 2;
k -= 2;
if (k * a < 2) cout << 2 << endl;
else cout << k * a << endl;
}
}
更准确地说,n是奇数,所以2na>=2a,又根据a范围,2a>2,因此无需max{2na,2},直接输出2na即可
include
using namespace std;