Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <sstream>
- using namespace std;
- bool checkPrime(int x) {
- for (int i = 2; i <= sqrt(x); i++) {
- if (x % i == 0) {
- return false;
- }
- }
- return true;
- }
- int findFactor(int x){
- int prime = 0;
- for (int i = x; i > 1; i--) {
- for (int j = 2; j <= x; j++) {
- if (checkPrime(j) && i % j == 0) {
- int temp = i;
- while (temp % j == 0) {
- prime++;
- temp /= j;
- }
- }
- }
- }
- return prime;
- }
- queue <int> split(const string& s, char delim) {
- queue <int> result;
- stringstream ss(s);
- string item;
- while(getline(ss, item, delim)){
- result.push(stoi(item));
- }
- return result;
- }
- int main(){
- string input, out = "";
- getline(cin, input);
- queue<int> q = split(input, ' ');
- while (!q.empty()){
- int temp = q.front(); q.pop();
- bool found = 0;
- for(int i = 2; i <= temp*5; i++){
- if(findFactor(i) == temp){
- out += to_string(i) + "!";
- found = true;
- break;
- }
- }
- if (!found)
- out += "N ";
- }
- cout << out << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement