Solo i due testcase 014 e 029 mi danno output non corrett, il resto è tutto giusto. Quale è l’errore?
Codice
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
int my_pow(int x, int y){
int r = 1;
for(int i = 0; i < y; i ++) r *= x;
return r;
}
int main(){
int n, p = 0;
int i = 2, j = 2;
in >> n;
while(my_pow(i, j) <= n && n > 3){
while(p < n){
p = my_pow(i, j);
j ++;
}
if(p > n) p = my_pow(i, j - 2);
i ++;
j = 2;
}
if(n > 3) out << p;
else if(n > 0){
out << 1;
} else out << 0;
}