题意
定义函数rad(x)为x的质因子之积
给定c,求是否能找到两个正整数a,b,使得a+b=c且c>rad(abc)
T(1<=T<=10)
c(1<=c<=1e18)
Sample Input
3
4
18
30
Sample Output
yes
yes
no
思路
对于一个符合条件的数n,我们可以得出,该数一定可以拆分成n=abccd的模式
即该数的因子中一定有某个完全平方数。
那么问题就被简化成了判断是否含有一个完全平方因子,不过我们观察到c<=1e18,那么需要枚举i^2中i的取值范围为i<=1e9的质数,大约为1e8
显然这个复杂度我们是接受不了的,我们需要优化复杂度
我们可以观察到这样一个规律,如果c没有在1-1e12内的完全平方数的因子,那么将c除去前面那些因子,得到c’,如果c有1e12以上的完全平方数因子,那么该因子一定为c’
因此我们可以暴力枚举1e6以内的质数,对于大于1e12的因数进行一次check即可
CODE
#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MAXN 100050
LL read()
{
LL w = 1, x = 0;
char ch = 0;
while (ch < '0' || ch>'9')
{
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + (ch - '0');
ch = getchar();
}
return w * x;
}
LL n, m, cnt, t, prime[1000005],p[1000005];//prime记录素数
bool v[1000005];//记录是否是合数
int main()
{
n = 1000005;
v[0] = 1;//0不是素数
v[1] = 1;//1不是素数
for (register int i = 2; i <= n; i++)
{
if (!v[i])//如果i是素数 用prime记录,prime里面的素数严格递增
{
prime[++cnt] = i;
}
for (register int j = 1; j <= cnt; j++)//遍历所有素数
{
if (prime[j] * i > n)
{
break;
}
v[prime[j] * i] = 1;
if (i % prime[j] == 0)//如果该数(i)大于等于这个数的最小质因子,就跳出
//详见 https://www.cnblogs.com/jason2003/p/9761296.html 解释
{
break;
}
}
}
for (register int i = 1; i <= cnt; i++)
{
p[i] = prime[i] * prime[i];
}
int t = read();
while (t--)
{
n = read();
LL nn = n;
bool ok = 1;
for (register int i = 1; i <= cnt; i++)
{
if (n % p[i] == 0)
{
ok = 0;
cout << "yes" << endl;
break;
}
if (nn % prime[i] == 0)
{
nn /= prime[i];
}
}
if (ok)
{
LL ss = sqrt(nn);
if (ss * ss == nn&&nn!=1)
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
}
}
return 0;
}