HDU 2040 亲和数

 

一道没想到居然没有超时的题,思路就是找小的那个数,然后取一半一直往下递减,找到所有约数的和,然后和较大的数比较是否相等。

#include <stdio.h>
#include <iostream>
#include <math.h>
#include <fstream>

using namespace std;

void main()
{
	int a,b;

	int n;
	cin>>n;
	while(n--)
	{
		scanf("%d %d",&a,&b);
		int nMin = a<b?a:b;
		int nMax = a>b?a:b;
		int sum = 0;
		for(int i=nMin/2;i>0;i--)
		{
			if(nMin % i == 0)
				sum += i;
		}
		if(sum == nMax)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

 

相关文章:

  • 2021-11-15
  • 2022-12-23
  • 2022-01-21
  • 2021-10-30
  • 2022-01-27
  • 2021-12-16
猜你喜欢
  • 2021-05-15
  • 2021-08-08
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2021-04-09
  • 2022-02-03
相关资源
相似解决方案