| ||||||||||
| 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 | |||||||||
Re:用JAVA的帮看看,WHY RE?要疯了In Reply To:用JAVA的帮看看,WHY RE?要疯了 Posted by:gostopsb at 2007-01-02 22:15:29 > import java.util.*;
> public class P1595
> {
> private static final int MAX = 3000;
> public static boolean isPrime(int n)
> {
> for(int i=2;i<Math.sqrt((double)n)+1;i++)
> {
> if(n%i==0)
> {
> return false;
> }
> }
> return true;
> }
> /**
> * @param args
> */
> public static void main(String[] args)
> {
> // TODO 自动生成方法存根
> Scanner sc = new Scanner(System.in);
>
> boolean[] primeList=new boolean[MAX];
>
> ///////////////建立质数表
> primeList[1]=true;
> primeList[2]=true;
> for(int i=3;i<MAX;i++)
> {
> if(isPrime(i))
> {
> primeList[i]=true;
> }
> }
> ////////////建立质数表
>
> /////////建立从1到N之间质数个数表
> int[] count=new int[MAX];
>
> count[1]=1;
> count[2]=2;
>
> for(int i=3;i<MAX;i++)
> {
> if(isPrime(i))
> {
> count[i]=count[i-1]+1;
> }
> else
> {
> count[i]=count[i-1];
> }
> }
> /////////建立从1到N之间质数个数表
>
> int n=sc.nextInt();
> int c=sc.nextInt();
>
> LinkedList<Integer> result=new LinkedList<Integer>();
> int index=0;
> while(true)
> {
> index=0;
> result.clear();
> int cc=c;
> if(count[n]%2==0)
> {
> cc=2*c;
> }
> else
> {
> cc=2*c-1;
> }
>
> for(int i=1;index<n&&i<=n;i++)
> {
> if(primeList[i])
> {
> result.add(i);
> index++;
> }
> }
> if(cc>count[n])
> {
> cc=count[n];
> }
>
>
> System.out.print(n+" "+c+":");
>
> for(int i=(count[n]-cc)/2;i<(count[n]-cc)/2+cc;i++)
> {
>
> System.out.print(" "+result.get(i));
> }
> System.out.println();
> System.out.println();
> n=sc.nextInt();
> c=sc.nextInt();
>
> }
>
>
> }
>
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator