#4001: TLE了....


a5480a5480 (歐歐)

學校 : 不指定學校
編號 : 12402
來源 : [123.195.69.222]
最後登入時間 :
2023-03-31 12:40:34
d709. 判断质数(一) -- 判断质数系列 | From: [123.195.112.138] | 發表日期 : 2010-07-17 11:10

import java.util.Scanner;

public class d709{
 public static void main(String args[]){
  Scanner cin = new Scanner(System.in);
  long x = 3 , count = 0;
  
  while(x != 0 && count != 1000000){
   int num , decide = 3;
   x = Integer.parseInt(cin.nextLine());
   
   if(x % 2 == 0 && x !=2 && x != 0 || x == 1){
    System.out.println("1");
    decide = 0 ;
   }else {
    num = (int) Math.sqrt((double)x);
    for(int i = 3 ; i <= num ; i+=2){
     if( x % i == 0 ){
      System.out.println("1");
      decide = 0;
      break;
     }else
      decide = 1;
    }
   }
   if(decide == 1 || x == 2 || x == 3 || x == 5 || x == 7)
    System.out.println("0");
   count++;
  }
 }
}

 有人可以給我建議嗎|||,謝謝

 
ZeroJudge Forum