# Prime number:
n = int(input("Please enter your input number: "))
if n>1:
for i in range(2,n):
if n%i == 0:
print("%d is a Not Prime."%n)
break
else:
print("%d is a Prime."%n)
else:
print("%d is a Not Prime."%n)
# Use to Definition Function:
'''
def Prime_number_chcek(n):
if n>1:
for i in range(2,n):
if n%i == 0:
return ("%d is a Not Prime."%n)
return ("%d is a Prime."%n)
return ("%d is a Not Prime."%n)
# Main Driver:
if __name__=="__main__":
n = int(input("Enter your input number: "))
print(Prime_number_chcek(n))
'''
// A optimized school method based C++ program to check
// if a number is prime
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// Driver Program to test above function
int main()
{
isPrime(11) ? cout << " true
" : cout << " false
";
isPrime(15) ? cout << " true
" : cout << " false
";
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=2;i<sqrt(n)+1;i++){
if(n%i==0){
cout<<"number is not a prime";
return 0;
}
}
cout<<"number is a prime";
return 0;
}
# Prime number:
n = int(input("Please enter your input number: "))
if n>1:
for i in range(2,n):
if n%i == 0:
print("%d is a Not Prime."%n)
break
else:
print("%d is a Prime."%n)
else:
print("%d is a Not Prime."%n)
# Use to Definition Function:
'''
def Prime_number_chcek(n):
if n>1:
for i in range(2,n):
if n%i == 0:
return ("%d is a Not Prime."%n)
return ("%d is a Prime."%n)
return ("%d is a Not Prime."%n)
# Main Driver:
if __name__=="__main__":
n = int(input("Enter your input number: "))
print(Prime_number_chcek(n))
'''
// A optimized school method based C++ program to check
// if a number is prime
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// Driver Program to test above function
int main()
{
isPrime(11) ? cout << " true
" : cout << " false
";
isPrime(15) ? cout << " true
" : cout << " false
";
return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
for(int i=2;i<sqrt(n)+1;i++){
if(n%i==0){
cout<<"number is not a prime";
return 0;
}
}
cout<<"number is a prime";
return 0;
}