This repository has been archived on 2024-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
Schule/Mathe/befreundete Zahlen/befreundete Zahlen2.cpp

38 lines
884 B
C++
Raw Normal View History

2017-04-02 16:42:35 +02:00
#include<iostream>
#include<string>
#include<sstream>
2017-04-08 18:03:33 +02:00
#include<conio.h>
2017-04-02 16:42:35 +02:00
int main()
{
std::string input;
2017-04-08 18:03:33 +02:00
unsigned long long max = 1;
2017-04-02 16:42:35 +02:00
2017-04-02 17:00:43 +02:00
std::cout << "Gib an bis zu welcher Zahl nach befreundeten Zahlen gesucht werden soll: ";
2017-04-02 16:42:35 +02:00
getline(std::cin, input);
std::stringstream(input) >> max;
if(max<284)
{
std::cout << "\nEs wurden keine befreundeten Zahlen gefunden.";
2017-04-08 18:03:33 +02:00
getch();
2017-04-02 16:42:35 +02:00
return(0);
}
std::cout << "\nbefreundete Zahlen sind:\n";
for(unsigned long long number = 284; number<=max; number++)
{
unsigned long long sum = 0, sum2 = 0;
for(unsigned long long factor = 1; factor*2<=number; factor++) if(number%factor==0) sum += factor;
if(sum<number && sum>=220) for(unsigned long long factor = 1; factor*2<=sum; factor++) if(sum%factor==0) sum2 += factor;
if(sum2==number) std::cout << sum << " und " << sum2 << "\n";
}
2017-04-08 18:03:33 +02:00
getch();
2017-04-02 16:42:35 +02:00
return(0);
}