4.02

 avatar
NguyenAnhQuan
c_cpp
6 months ago
470 B
8
Indexable
Never
#include <iostream>
using namespace std;
#include <math.h>

int sum_all_square(int n)
{

	int sum = 0;

	for (int i = 1 ; i * i <= n; i++)
		if (n % i == 0)
		{
			int a = i, b = n / i;

			if (i == sqrt(n) && pow(int(sqrt(i)), 2) == i) {sum += i; continue;}
			if (pow(int(sqrt(a)), 2) == a) sum += a;
			if (pow(int(sqrt(b)), 2) == b) sum += b;

		}

	return sum;
}


int main() {
    int n;
    cin>>n;
    cout << sum_all_square(n);
}