Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- // determina daca numarul x este puternic
- // returneaza 1 in caz afirmativ, 0 in caz negativ
- unsigned int puternic(unsigned int x) {
- unsigned int aux = x;
- for(unsigned int div = 2; div <= aux; ++div) {
- if(aux%div == 0) {
- if(x%(div*div) != 0) {
- return 0;
- }
- while(aux%div == 0) {
- aux /= div;
- }
- }
- }
- return 1;
- }
- int main() {
- ofstream fout("numere.out");
- unsigned int n;
- cin >> n;
- // am observat ca primul numar puternic este 4
- // trec prin toate numerele din [4, n] si le afisez doar pe cele puternice
- for(unsigned int i = 4; i <= n; ++i) {
- if(puternic(i)) {
- fout << i << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement