社区讨论
过但问
P8778[蓝桥杯 2022 省 A] 数的拆分参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mlnma7fa
- 此快照首次捕获于
- 2026/02/15 18:43 4 天前
- 此快照最后确认于
- 2026/02/16 13:56 3 天前
分代码:
CPP#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> pr;
bool isp[4005];
void eula(int N){
memset(isp, 1, sizeof isp);
isp[1] = 0;
for(int i = 2; i <= N; ++ i){
if(isp[i])
pr.push_back(i);
for(int j = 0; j < pr.size() && i * pr[j] <= N; ++ j){
isp[i * pr[j]] = 0;
if(i % pr[j] == 0)
break;
}
}
}
bool check2(int x){
int y = sqrt(x);
return y * y == x;
}
bool check3(int x){
int y = cbrt(x);
return y * y * y == x;
}
void solve(){
int x;
cin >> x;
for(int p : pr)
if(x % p == 0){
int y = 0;
while(x % p == 0)
x /= p, ++ y;
if(y == 1){
cout << "no\n";
return;
}
}
cout << ((check2(x) || check3(x)) ? "yes\n" : "no\n");
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
eula(4000);
int T;
cin >> T;
while(T --)
solve();
return 0;
}
分代码:
CPP#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> pr;
bool isp[4005];
void eula(int N){
memset(isp, 1, sizeof isp);
isp[1] = 0;
for(int i = 2; i <= N; ++ i){
if(isp[i])
pr.push_back(i);
for(int j = 0; j < pr.size() && i * pr[j] <= N; ++ j){
isp[i * pr[j]] = 0;
if(i % pr[j] == 0)
break;
}
}
}
bool check2(int x){
int y = sqrt(x);
if(y * y == x) return true;
if((y+1)*(y+1) == x) return true;
if(y > 0 && (y-1)*(y-1) == x) return true;
return false;
}
bool check3(int x){
int y = cbrt(x);
if(y * y * y == x) return true;
if((y+1)*(y+1)*(y+1) == x) return true;
if(y > 0 && (y-1)*(y-1)*(y-1) == x) return true;
return false;
}
void solve(){
int x;
cin >> x;
for(int p : pr)
if(x % p == 0){
int y = 0;
while(x % p == 0)
x /= p, ++ y;
if(y == 1){
cout << "no\n";
return;
}
}
cout << ((check2(x) || check3(x)) ? "yes\n" : "no\n");
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
eula(4000);
int T;
cin >> T;
while(T --)
solve();
return 0;
}
为什么检查了 就过了
回复
共 1 条回复,欢迎继续交流。
正在加载回复...