Advertisement
Guest User

bla

a guest
Nov 21st, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <sstream>
  4. using namespace std;
  5.  
  6. bool checkPrime(int x) {
  7. for (int i = 2; i <= sqrt(x); i++) {
  8. if (x % i == 0) {
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14.  
  15. int findFactor(int x){
  16. int prime = 0;
  17. for (int i = x; i > 1; i--) {
  18. for (int j = 2; j <= x; j++) {
  19. if (checkPrime(j) && i % j == 0) {
  20. int temp = i;
  21. while (temp % j == 0) {
  22. prime++;
  23. temp /= j;
  24. }
  25. }
  26. }
  27. }
  28. return prime;
  29. }
  30.  
  31. queue <int> split(const string& s, char delim) {
  32. queue <int> result;
  33. stringstream ss(s);
  34. string item;
  35. while(getline(ss, item, delim)){
  36. result.push(stoi(item));
  37. }
  38. return result;
  39. }
  40.  
  41. int main(){
  42. string input, out = "";
  43. getline(cin, input);
  44. queue<int> q = split(input, ' ');
  45. while (!q.empty()){
  46. int temp = q.front(); q.pop();
  47. bool found = 0;
  48. for(int i = 2; i <= temp*5; i++){
  49. if(findFactor(i) == temp){
  50. out += to_string(i) + "!";
  51. found = true;
  52. break;
  53. }
  54. }
  55. if (!found)
  56. out += "N ";
  57. }
  58. cout << out << endl;
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement