1 条题解
-
0
20分代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL a[110]; bool pd(LL x) { if(x<2) return 0; for(LL i=2;i<x;i++) if(x%i==0) { return 0; } return 1; } int main() { int n;scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%lld", &a[i]); if( pd(a[i])==1 ) { printf("%lld ", a[i]); } } return 0; }40分代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL a[110]; bool pd(LL x) { if(x<2) return 0; for(LL i=2;i<=x/2;i++) if(x%i==0) { return 0; } return 1; } int main() { int n;scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%lld", &a[i]); if( pd(a[i])==1 ) { printf("%lld ", a[i]); } } return 0; }100分代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; LL a[110]; bool pd(LL x) { if(x<2) return 0; for(LL i=2;i<=sqrt(x+1);i++) if(x%i==0) { return 0; } return 1; } int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); if( pd(a[i])==1 ) { printf("%lld ",a[i]); } } return 0; }
- 1
信息
- ID
- 17
- 时间
- 300ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- 递交数
- 1576
- 已通过
- 138
- 上传者