Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool primer(int n) {
- if (n <= 1) return false;
- for (int i = 2; i*i <= n; ++i) {
- if (n%i == 0) return false;
- }
- return true;
- }
- bool es_poderos(int n){
- int cont = 0;
- bool duesvegades = true;
- int i = 2;
- while (duesvegades and n > 1){
- while(primer(i) and n%i == 0){
- ++cont;
- if (cont < 2) duesvegades = false;
- else duesvegades = true;
- n = n/i;
- }
- ++i;
- cont = 0;
- }
- if (duesvegades) return true;
- else return false;
- }
- int main(){
- int n;
- while (cin >> n){
- cout << 1;
- for (int i = 2; i <= n; i++){
- if (es_poderos(i)) cout << "," << i;
- }
- cout << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement