NT01
Cho số nguyên dương \(n\).
Yêu cầu: Cho biết số \(n\) có phải là số nguyên tố không?
Input
- Gồm một dòng chứa số nguyên dương \(n(|n|≤10^{12} ).\)
Output
- Ghi \(YES\) nếu \(n\) là số nguyên tố, ngược lại ghi \(NO\).
Sample Input
7
Sample Output
YES
Sample Input
6
Sample Output
NO
Comments
include <bits/stdc++.h>
define ll long long
define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std; ll n; void messi() { cin>>n;} int NTO(ll x) {ll d=0; fr(i, 1, sqrt(x)) if (x%i==0) { d++; if(i!=x/i) d++; } if (d==2) return 1; else return 0; } int main() { messi(); if(NTO(n)==1) cout<<"YES"; else cout<<"NO"; }