Created
June 7, 2019 01:38
-
-
Save youchen/a0e24049c01e74580d45b82879fcc3a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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