| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请问哪里错了?import java.lang.Math;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num[];
num=new int[200];
int k=0;
num[0]=1;
int count=1;
for(int i=2; i<=1000; i++)
{
k=0;
for(int j=2; j<=Math.sqrt(i); j++)
if(i%j==0)
{
k=1;
break;
}
if(k==0)
{
num[count]=i;
count++;
// System.out.println(i);
}
}
Scanner in;
in=new Scanner(System.in);
while(in.hasNext())
{
int a,b;
int i;
a=in.nextInt();
b=in.nextInt();
for(i=178; i>=1; i--)
if(num[i]>a && num[i-1]<=a)
break;
// System.out.print(i+"\n");
System.out.print(a+" "+b+":"+" ");
if(2*b>=i)
{
for(int j=0; j<i; j++)
System.out.print(num[j]+" ");
System.out.println();
}
else if(i%2==0)
{
for(int j=i/2-b; j<=i/2+b-1; j++)
System.out.print(num[j]+" ");
System.out.println();
}
else
{
for(int j=i/2-b+1; j<=i/2+b-1; j++)
System.out.print(num[j]+" ");
System.out.println();
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator