B. Prime checking – Codeforces Problem Solution in C++

Disclaimer: Make sure you tried enough before checking the solution

Problem: https://codeforces.com/group/MWSDmqGsZm/contest/223338/problem/B

#include<bits/stdc++.h>
using namespace std;
int main() {
   long long num;
   cin>>num;
   bool isPrime = true;
   
   if(num == 0 || num == 1){
   		isPrime = false;
   }
   for(int i=2;i<= sqrt(num);i++){ //
   		if(num % i == 0){
   			isPrime = false;
   			break;
		}
   }
   if(isPrime){
   	cout<<"YES"<<endl;
   } else {
   	   	cout<<"NO"<<endl;
   }
}

Assiut University Training – Newcomers Solution Math – Geometry

Leave a Comment