1 条题解
-
0
C :
#include <math.h> #include<stdio.h> int main( ) { int m,i,k,n=0; int flag=0; for(m=101; m<=200; m+=2) { k=sqrt(m); for (i=2;i<=k;i++){ if (m%i==0) break;} if (i>k){ if (flag) printf(" %d",m); else printf("%d",m); n=n+1; flag=1; if (n%7==0) {printf("\n"); flag=0; } } } return 0; }
C++ :
#include<iostream> #include<cmath> using namespace std; bool hanshu(int a){ for(int i=2;i<=sqrt(a);i++){ if(a%i == 0) return false; } return true; }; int main(){ int j=1; for(int i=100;i<200;i++){ if(hanshu(i) == true){ if(j++%7==0) cout<<i<<endl; else cout<<i<<" "; } } return 0; }
Java :
public class Main { public static void main(String[] args) { int count = 0; for(int i = 100;i<201;i++){ boolean a = true; for(int j = 2;j<i;j++) { if (i%j==0) a =false; } if(a == true) { count++; if(count%7==0) System.out.println(i); else {System.out.print(i); System.out.print(" "); } } } } }
- 1
信息
- ID
- 1028
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者