Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- std::vector<int> ProstiFaktori(int n)
- {
- std::vector<int> v;
- if(n == 1)
- v.push_back(n);
- else
- {
- int a(n), b;
- int c(a%2);
- while(c == 0)
- {
- b = a/2;
- v.push_back(2);
- a = b;
- c = a%2;
- }
- for(int i(3); i<=a; i=i+2)
- {
- int c(a%i);
- while(c == 0)
- {
- b = a/i;
- v.push_back(i);
- a = b;
- c = a%i;
- }
- }
- }
- return v;
- }
- int main()
- {
- std::vector<int> test = ProstiFaktori(100);
- for(unsigned int i(0); i < test.size(); i++)
- std::cout << test[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement