Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- long s(long);
- long s(long n) {
- long sum = 0;
- long m;
- m = (long) sqrt(n);
- for (long i = 2; i < m; i++)
- if ((n % i) == 0) sum += (i + (n/i));
- if (n>1) sum += 1;
- if ((m*m) == n) sum += m;
- return sum;
- }
- int main() {
- long a,b;
- cout << "Enter lower bound of Amicable Pairs: ";
- cin >> a;
- cout << "Enter upper bound of Amicable Pairs: ";
- cin >> b;
- long j;
- for (long i=a; i<=b; i++) {
- j = s(i);
- if ((i<j) && (i == s(j)))
- cout << i << " and " << j << " are Amicable Pairs." << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment