mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-27 20:14:04 +08:00
formatting source-code for 1d7a73ea58
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
* \brief A C++ Program to check whether a pair of number is [amicable pair](https://en.wikipedia.org/wiki/Amicable_numbers) or not.
|
* \brief A C++ Program to check whether a pair of number is [amicable
|
||||||
*
|
* pair](https://en.wikipedia.org/wiki/Amicable_numbers) or not.
|
||||||
|
*
|
||||||
* \details
|
* \details
|
||||||
* Amicable Pair are two positive integers such that sum of the proper divisor
|
* Amicable Pair are two positive integers such that sum of the proper divisor
|
||||||
* of each number is equal to the other number.
|
* of each number is equal to the other number.
|
||||||
* @author iamnambiar
|
* @author iamnambiar
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to calculate the sum of all the proper divisor
|
* Function to calculate the sum of all the proper divisor
|
||||||
* of an integer.
|
* of an integer.
|
||||||
* @param num First number.
|
* @param num First number.
|
||||||
* @return Sum of the proper divisor of the number.
|
* @return Sum of the proper divisor of the number.
|
||||||
@@ -20,7 +21,8 @@
|
|||||||
int sum_of_divisor(int num) {
|
int sum_of_divisor(int num) {
|
||||||
// Variable to store the sum of all proper divisors.
|
// Variable to store the sum of all proper divisors.
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
// Below loop condition helps to reduce Time complexity by a factor of square root of the number.
|
// Below loop condition helps to reduce Time complexity by a factor of
|
||||||
|
// square root of the number.
|
||||||
for (int div = 2; div * div <= num; ++div) {
|
for (int div = 2; div * div <= num; ++div) {
|
||||||
// Check 'div' is divisor of 'num'.
|
// Check 'div' is divisor of 'num'.
|
||||||
if (num % div == 0) {
|
if (num % div == 0) {
|
||||||
@@ -48,7 +50,7 @@ bool are_amicable(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function for testing the is_amicable() with
|
* Function for testing the is_amicable() with
|
||||||
* all the test cases.
|
* all the test cases.
|
||||||
*/
|
*/
|
||||||
void test() {
|
void test() {
|
||||||
@@ -62,7 +64,7 @@ void test() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Function
|
* Main Function
|
||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
test();
|
test();
|
||||||
std::cout << "Assertion Success." << std::endl;
|
std::cout << "Assertion Success." << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user