Debug

시간 제한1초메모리 제한2048 MB

요약
n이 1e9 이하일 때 소수이면 yes, 아니면 no를 출력하도록 코드를 빠르게 고친다.
난이도

쉬움10점 중 3점

유형
정수론, 수학
정답자
아직 제출이 없습니다

문제

You just joined a new team to participate in the FPC, because the previous member left the team frustrated. Frustrated that he could not beat a time limit1 of a certain problem of an earlier FPC. To show you indeed posses the skills to solve problems during a FPC, you decide to solve the problem the other member could not. Unfortunately, he never told anyone which problem he was actually trying to solve. Luckily, you still got his code!

Your task is to debug the problem his code is solving and speed it up. You may assume that in its current state, it is correct but too slow. The (Java) code is given below.

import java.util.Scanner;

class D {
    public static int n(int n) {
        int p = 1;
        if (n == 1 || n == 0) p = 0;
        for (int i = 1; i < n; i++) {
            if (i == 1) continue;
            if (n % i == 0) p = 0;
        }
        return p;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if (n(sc.nextInt()) == 1) System.out.println("yes");
        else System.out.println("no");
    }
}

1This was based on the text "Correct but TIME LIMIT! AARGH!" being scratched in the wall.

입력

As can be seen in the provided code. The only input is an integer 0≤n≤1090 \leq n \leq 10^9.

출력

Keep the same output as provided in the code. You only need to speed up things.

예제

이 문제는 공개된 예제가 없습니다.