没有测试条件稍后有机会测试,既然姥姥说那个测试点是卡计算重复因子的算法,所以我们用k1标记,防止重复因子出现
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int k;
bool check()
{
int k1[10000]={0};
int l = 0;
int a[100];
for (int i = 1; i*i<=k; i++)
{
if (k % i == 0&&k1[i]==0)
{
k1[i]=1;
a[l++] = i;
if(i*i!=k)
a[l++] = k / i;
}
}
for (int i = 0; i < l; i++)
{
for (int j = 0; j < l; j++)
{
for (int p = 0; p < l; p++)
{
for (int o =0; o < l; o++)
{
if(a[i]!=a[j]!=a[p]!=a[o])
if (k%(a[i] + a[j] + a[p] + a[o]) == 0 )
return true;
}
}
}
}
return false;
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> k;
if (check() == false)
cout << "No" << endl;
else
{
cout << "Yes" << endl;
}
}
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/41c1480f238a027ed923f9ce769d9ffe.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4bf54a164dad566ba7ebfdfb84c74a91.png)
测试点3过不了,网上代码很多也过不了,我再想想
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int k;
bool check()
{
int l = 0;
int a[100];
for (int i = 1; i*i<=k; i++)
{
if (k % i == 0)
{
a[l++] = i;
if(i*i!=k)
a[l++] = k / i;
}
}
for (int i = 0; i < l; i++)
{
for (int j = 0; j < l; j++)
{
for (int p = 0; p < l; p++)
{
for (int o =0; o < l; o++)
{
if(a[i]!=a[j]!=a[p]!=a[o])
if (k%(a[i] + a[j] + a[p] + a[o]) == 0 )
return true;
}
}
}
}
return false;
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> k;
if (check() == false)
cout << "No" << endl;
else
{
cout << "Yes" << endl;
}
}
return 0;
}