Skip to content

Instantly share code, notes, and snippets.

@youchen
Created June 7, 2019 01:41
Show Gist options
  • Save youchen/0df27b46155457d00624a8afa60c6a24 to your computer and use it in GitHub Desktop.
Save youchen/0df27b46155457d00624a8afa60c6a24 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
#include <string>
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;
}
bool isPrimeDay(string date){
int dateLength = date.length();
for (int i = 0; i < dateLength; i++){
if (!isPrime(stoi(date.substr(i, dateLength)))) {
return false;
}
}
return true;
}
void findPrimeDay(int yStart, int yEnd) {
int date;
for (int y = yStart; y <= yEnd; y++){
for (int m = 1; m <= 12; m++){
for (int d = 1; d <= 31; d++){
if ( !(m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12) and d == 31){
continue;
}
date = y * 10000 + m * 100 + d;
if (isPrimeDay(std::to_string(date))) {
cout << date << endl;
}
}
}
}
}
int main(){
findPrimeDay(1, 3000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment