This file contains 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 <cmath> | |
#include <cstdio> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <cstdio> | |
#include <iostream> | |
#include <memory> | |
#include <stdexcept> | |
#include <string> | |
using namespace std; | |
std::string exec(const string &cmd) { | |
char buffer[128]; | |
std::string result = ""; | |
std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose); | |
if (!pipe) throw std::runtime_error("popen() failed!"); | |
while (!feof(pipe.get())) { | |
if (fgets(buffer, 128, pipe.get()) != NULL) | |
result += buffer; | |
} | |
return result; | |
} | |
int main() { | |
const string pre = "factor "; | |
string line; | |
getline(cin, line); // skip count line | |
while (getline(cin, line)) { | |
bool prime = exec(pre + line).size() == (2 * line.size() + 3); | |
cout << (prime ? "Prime" : "Not prime") << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment