Verificare pătrat perfect

#include <iostream>
using namespace std;

int main()
{
    unsigned n,ok=1,f=2,p;
    cin>>n;
    while(n!=1&&ok==1)
    {
        p=0;
        while(n%f==0)
        {
            n=n/f;
            ++p;
        }
        if(p%2!=0)ok=0;
        ++f;
    }
    if(ok==1)cout<<"da";
    else cout<<"nu";
    return 0;
}