TopCoder

User's AC Ratio

88.5% (92/104)

Submission's AC Ratio

60.9% (151/248)

Tags

Description

給你一個正整數,請問他是不是質數呢?

剛學會質數判定的小喵,迫不及待的想試試身手!

但你也知道,可憐的小喵獲得了 WA :((

快幫幫小喵找到 bug 吧!

請給出 edit distance 與下列程式碼不超過 $2$ 的解。

// by =^● ⋏ ●^=
#include <bits/stdc++.h>
using namespace std;
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        int n;
        scanf("%d",&n);
        if(n==1) puts("NO"); // meow!
        else {
            int up = sqrt(n)+1;
            for(int i=2;i<=up;i++)
              if(n%i==0)up=0;
            if(up==0) puts("NO");
            else puts("YES");
        }
    }
    return 0;
}

Input Format

第一行有一個正整數 $T$,代表總共有幾筆測試資料。
每筆測試資料為一行一個整數 $N$。

  • $1 \le T \le 100$
  • $1 \le N \le 2 \times 10^ 9$

Output Format

對於每筆測試資料,請輸出 YES 或 NO,代表 $N$ 是不是質數。

Sample Input 1

3
3
6
1000000007

Sample Output 1

YES
NO
YES

Hints

Problem Source

Subtasks

No. Testdata Range Score
1 0 1

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Output Limit (KiB) Subtasks
0 1000 262144 262144 1