知道公式很好做的一道题
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int prime[maxn];
int vis[maxn], cnt, p;
typedef long long ll;
void init()
{
cnt = 0;
memset(vis, 0, sizeof(vis));
for (int i = 2; i<maxn; i++)
{
if (!vis[i])
{
prime[cnt++] = i;
for (int j = i + i; j<maxn; j += i)
vis[j] = 1;
}
}
}
int yz[maxn];
int syzfj(int n)
{
int x = n, tmp = 0, hh = 0;
for (int i = 0; i<cnt&&prime[i] <= n; i++)
{
if (n%prime[i] == 0)
{
tmp++; hh = 0;
while (x%prime[i] == 0)
{
hh++;
x /= prime[i];
}
//cout << hh<<" " <<prime[i] << endl;
if (hh >= 2)
return 0;
}
}
if (x > 1)
tmp++;
if (tmp % 2 == 0)
return 1;
else
return -1;
}
int main()
{
int n, t;
init();
while (cin >> n)
{
if (n >= 2)
cout << syzfj(n) << endl;
else
cout << "1" << endl;
}
return 0;
}