资深守护
定义 a[1000010],b[110];
bool qq(int n){
if(n==1) return false;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) 返回假;
}
返回真;
}
int n,maxn=0;
cin>>n;
循环1~n{
cin>>b[i];
maxn=max(maxn,b[i]);
}
循环2~maxn{
if(a[i]==0){
循环2*i~maxn j+=i{
a[j]++;
}
}
}
循环1~n{
if(qq(b[i])) a[b[i]]=1;
输出a[b[i]]<<endl;
}
主函数:
中级光能
三个函数
一个判断质数
略......
一个统计质因数
- int workd(int a){
- int cnt=0;
- for(int i=1;i<=a;i++){
- if(a%i==0&&Judge(i)){
- cnt++;
- }
- }
- return cnt;
- }
还有int main()
略......
资深光能
#include<iostream>
#include<cmath>
int a[1000010],b[110];
bool qq(int n){
if(n==1) return false;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
int main()
{
int n,maxn=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i];
maxn=max(maxn,b[i]);
}
for(int i=2;i<=maxn;i++){
if(a[i]==0){
for(int j=2*i;j<=maxn;j+=i){
a[j]++;
}
}
}
for(int i=1;i<=n;i++){
if(qq(b[i])) a[b[i]]=1;
cout<<a[b[i]]<<endl;
}
return 0;
}
@荣逸乐@哪错了
资深守护
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
int a[1000010],b[110];
bool f(int n){
if(n==1) return false;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) return 0;
}
return 1;
}
int main(){
int n,maxn=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i];
maxn=max(maxn,b[i]);
}
for(int i=2;i<=maxn;i++){
if(a[i]==0){
for(int j=2*i;j<=maxn;j+=i){
a[j]++;
}
}
}
for(int i=1;i<=n;i++){
if(f(b[i])) a[b[i]]=1;
cout<<a[b[i]]<<endl;
}
return 0;
}