Skip to content

Instantly share code, notes, and snippets.

Created September 25, 2016 16:24
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#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