Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- bool IsPrime(int n) {
- if (n < 2)
- return false;
- if (n == 2)
- return true;
- for (int i = 2; i < n; i++) {
- if (n % i == 0)
- return false;
- }
- return true;
- }
- vector<int> Factorize(int n) {
- vector<int> ret;
- int i = 2;
- while (n > 1) {
- if (n % i == 0) {
- ret.push_back(i);
- n /= i;
- }
- else
- i++;
- }
- return ret;
- }
- int main()
- {
- setlocale(LC_ALL, "Polish");
- ifstream ff;
- ofstream out;
- out.open("wynik.txt");
- ff.open("liczby.txt");
- int c=0;
- int maks = 0;
- int liczba_maks = 0;
- for (int i = 0; i < 500; i++) {
- int a;
- ff >> a;
- /*if (!IsPrime(a)) {
- cout << a << endl;
- out << a << endl;
- c++;
- }*/
- if (!IsPrime(a)) {
- vector<int> liczby = Factorize(a);
- int suma = 0;
- for (int l : liczby)
- suma += l;
- if (suma > maks)
- {
- maks = suma;
- liczba_maks = a;
- }
- cout << a << ": ";
- for (int b : liczby) {
- cout << b << " ";
- }
- cout << endl;
- c++;
- }
- }
- cout << "Liczba, o największej sumie czynników to: ";
- cout << liczba_maks <<endl;
- out.flush();
- out.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment