#include <stdio.h>
#include <stdbool.h>
typedef struct ans{
int factor;
int squared;
bool imaginary;
} ans;
ans mysqrt(int);
void output(ans);
int main(void){
output(mysqrt(171));
output(mysqrt(0));
output(mysqrt(500));
output(mysqrt(1));
output(mysqrt(-171));
output(mysqrt(-500));
/*
this outputs
1 * i
not
i
but this is by design.
*/
output(mysqrt(-1));
}
ans mysqrt(int x){
int val;
ans ret;
if(x < 0){
ret.imaginary = true;
val = -x;
}else{
ret.imaginary = false;
val = x;
}
if(val == 0){
ret.factor = 0;
ret.squared = 1;
return ret;
}
ret.factor = 1;
for(int i = 2;;i++){
int square = i * i;
if(square > val){
break;
}
while(true){
if( val % square != 0){
break;
}
val /= square ;
ret.factor *= i;
continue;
}
}
ret.squared = val;
return ret;
}
void output(ans x){
if(x.squared == 1){
}else{
printf("%d * sqrt(%d)",x.
factor,x.
squared); }
if(x.imaginary == true){
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+IAojaW5jbHVkZSA8c3RkYm9vbC5oPgoKdHlwZWRlZiBzdHJ1Y3QgYW5zewoJaW50IGZhY3RvcjsKCWludCBzcXVhcmVkOwoJYm9vbCBpbWFnaW5hcnk7Cn0gYW5zOwoKYW5zIG15c3FydChpbnQpOwp2b2lkIG91dHB1dChhbnMpOwoKaW50IG1haW4odm9pZCl7ICAKCW91dHB1dChteXNxcnQoMTcxKSk7CglwcmludGYoIlxuIik7CglvdXRwdXQobXlzcXJ0KDApKTsKCXByaW50ZigiXG4iKTsKCglvdXRwdXQobXlzcXJ0KDUwMCkpOwoJcHJpbnRmKCJcbiIpOwoKCW91dHB1dChteXNxcnQoMSkpOwoJcHJpbnRmKCJcbiIpOwoKCW91dHB1dChteXNxcnQoLTE3MSkpOwoJcHJpbnRmKCJcbiIpOwoKCW91dHB1dChteXNxcnQoLTUwMCkpOwoJcHJpbnRmKCJcbiIpOwoKCgkvKiAKCQl0aGlzIG91dHB1dHMgCgkJCTEgKiBpCgkJbm90CgkJCWkKCQlidXQgdGhpcyB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