Skip to content

Instantly share code, notes, and snippets.

@youchen
Created June 7, 2019 01:38
Show Gist options
  • Save youchen/a0e24049c01e74580d45b82879fcc3a0 to your computer and use it in GitHub Desktop.
Save youchen/a0e24049c01e74580d45b82879fcc3a0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num){
if (num <= 1) return false;
for(int i = 2; i <= sqrt(num); i++){
if (num % i == 0) {
return false;
}
}
return true;
}
void isPrimeDay(string date){
int dateLength = date.length();
for (int i = 0; i < dateLength; i++){
if (!isPrime(stoi(date.substr(i, dateLength)))) {
cout << "This date is not prime day.";
return 0;
}
}
cout << "It's a prime day!";
return 0;
}
int main(){
string num;
cin >> num;
isPrimeDay(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment