My code:
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while( t-- ) {
int n, x = 0;
cin >> n;
if(n % 2 == 0)
cout << n/2 <<" "<< n/2 << endl;
else
int min = INT_MAX;
for(int i = 1; i*i <= n; i++) {
if(( n-i) % i == 0) {
int d = (n-i) / i;
if(d <= min) {
min = d;
x = i;
}
}
}
cout << x <<" "<< n-x <<endl;
}
// your code goes here
return 0;
}
The code gives some typical error which I am failing to deal with.
Please can anyone help me fix it.
C:\Users\HP\Desktop\Code\hello.cpp:21:20: error: invalid operands of types 'int'
and '' to binary 'operator<=' 21 | if(d<=min) | ~^~~~~
The problem is that you missed {}
for else
case in:
else
int min=INT_MAX;
for(int i=1;i*i<=n;i++)
Because of that, the scope of int min
is limited to the single line where it is defined. In if(d<=min)
, the compiler is seeing std::min()
function template instead (this is because you wrote using namespace std;
which is not recommended).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.