求大神看看代码怎么改,在Java是对的,在c++上代码有错,怎么改都不对,两个程序是一个目的
#include <iostream>#include <stdio.h>
using namespace std;
bool isPrime(unsigned long n) {
if (n <= 3) {
return n > 1;
} else if (n % 2 == 0 || n % 3 == 0) {
return false;
} else {
for (unsigned short i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}
return true;
}
}
int main(){
int a[1299],i,t=0;
for(i=2;i<10000;i++){
if(isPrime(i)){
a[t]=i;
t++;
}
}
int c,b,min=0,max=0,index=0;
while(index<10){
scanf_s("%d %d",&b,&c);
for(i=0;i<1299;i++){
if(i==0){
if(a[0]>=b){
min=0;
cout<<"min1"<<min<<endl;
}
}
while(i>=1){
if(a[i]>=b&&a[i-1]<=b){
cout<<"min2"<<min<<endl;
min=i;
}
if(a[i]>=c&&a[i-1]<=c){
max=i;
cout<<"max"<<max<<endl;
break;
}
}
}
if((max-min)==1){
cout<<"YES"<<endl;
}
if((max-min)!=1){
cout<<"NO"<<endl;
}
index++;
system("pause");
}
return 0;
}
package com.project.shea;
public class Shu {
public static boolean shua(int n){
for (int i = 2; i <= Math.sqrt(n); i++) {
if(n%i==0){
return false;
}
}
return true;
}
public static void main(String[] args) {
int a[]=new int[1299];
int t=0;
for (int i = 2; i < 100; i++) {
if(shua(i)){
a[t]=i;
t++;
System.out.println(i);
}
}
int aa=1,bb=3,min=0,max=0;
for (int i = 0; i < a.length; i++) {
if(a[0]>=aa){
min=0;
}
if(i>=1){
if(a[i]>=aa&&a[i-1]<=aa){
min=i;
}
if(a[i]>=bb&&a[i-1]<=bb){
max=i;
break;
}
}
}
System.out.println((3>=3&&2<=3));
System.out.println("a[0]="+a[0]);
System.out.println("a[1]="+a[1]);
System.out.println("a[2]="+a[2]);
System.out.println(min+"aaaaaaaaaaa"+max);
}
}