Advertisement
Guest User

C301A, Nombres poderosos

a guest
Oct 24th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool primer(int n) {
  5.         if (n <= 1) return false;
  6.         for (int i = 2; i*i <= n; ++i) {
  7.                 if (n%i == 0) return false;
  8.         }
  9.         return true;
  10. }
  11.  
  12.  
  13. bool es_poderos(int n){
  14.      int cont = 0;
  15.      bool duesvegades = true;
  16.      int i = 2;
  17.      while (duesvegades and n > 1){
  18.            while(primer(i) and n%i == 0){
  19.                     ++cont;
  20.                     if (cont < 2) duesvegades = false;
  21.                     else duesvegades = true;
  22.                     n = n/i;
  23.            }
  24.            ++i;
  25.            cont = 0;
  26.      }
  27.      if (duesvegades) return true;
  28.      else return false;
  29. }
  30.  
  31. int main(){
  32.     int n;
  33.     while (cin >> n){
  34.     cout << 1;
  35.     for (int i = 2; i <= n; i++){
  36.         if (es_poderos(i)) cout << "," << i;
  37.     }
  38.     cout << endl;
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement