(SPOJ) 3828 - Primo - Solução

import java.io.*;
import java.util.*;
import java.lang.Math;
import java.math.*;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.processa();
       
        System.exit(0);
    }
   
    void processa() throws NumberFormatException, IOException {
        String line = "";
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        line = br.readLine();
        StringTokenizer tokenizer = new StringTokenizer(line);
        int numero = Integer.valueOf(tokenizer.nextToken());

        boolean primo = true;
        for (int i = 2; i*i <= numero; i++) {
            if (numero%i == 0) {
                primo = false;
            }
        }
       
        if (primo) {
            System.out.println("sim");
        }
        else {
            System.out.println("nao");
        }
                       
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução