Algorithm


Problem Name: beecrowd | 1165

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1165

Prime Number

 

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

A Prime Number is a number that is divisible only by 1 (one) and by itself. For example the number 7 is Prime, because it can be divided only by 1 and by 7.

 

Input

 

The input contains several test cases. The first contains the number of test cases N (1 ≤ N ≤ 100). Each one of the following N lines contains an integer X (1 < X ≤ 107), that can be or not a prime number.

 

Output

 

For each test case print the message “X eh primo” (X is prime) or “X nao eh primo” (X isn't prime) according with to above specification.

 

 

 

Input Sample Output Sample

3
8
51
7

8 nao eh primo
51 nao eh primo
7 eh primo

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include <iomanip>
using namespace std;
int main(){
    int o;
    cin >> o;
    for(int l = 0; l  <  o; l++){
        int n;
        cin >> n;
        int primo = 0;
        for(int i = 1; i  <  n+1; i++){
            if(n % i == 0){
                primo+=1;
            }
        }
        if(primo == 2 and 1 != n){
            cout << n << " eh primo" << "\n";
        }
        else{
            cout << n << " nao eh primo" << "\n";
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 8 51 7

Output

x
+
cmd
8 nao eh primo 51 nao eh primo 7 eh primo

#2 Code Example with Python Programming

Code - Python Programming


for l in range(0, int(input())):
    n = int(input())
    primo = 0
    for i in range(1, n+1):
        if n % i == 0:
            primo+=1
    if primo == 2 and 1 != n:
        print(f'{n} eh primo')
    else:
        print(f'{n} nao eh primo')
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 8 51 7

Output

x
+
cmd
8 nao eh primo 51 nao eh primo 7 eh primo

#3 Code Example with Javascript Programming

Code - Javascript Programming



const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.split('\n');
let a = Number(lines.shift());
for(var l = 0; l  <  a; l++){
    let n = Number(lines.shift());
    let primo = 0;
    for(var i = 1; i  <  n+1; i++){
        if(n % i === 0){
            primo += 1;
        }
    }
    primo === 2 && 1 !== n ? console.log(`${n} eh primo`): console.log(`${n} nao eh primo`);
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 8 51 7

Output

x
+
cmd
8 nao eh primo 51 nao eh primo 7 eh primo
Advertisements

Demonstration


Previous
#1164 Beecrowd Online Judge Solution 1164 Perfect Number Solution in C++, Java, Js and Python
Next
#1171 Beecrowd Online Judge Solution 1171 Number Frequence Solution in C, C++, Java, Js and Python