[HDU] [2040] Amicable Numbers

Problem Description

Loading...

Problem Analysis

At the time, this problem looked complicated, so I didn’t dare to write it.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<stdio.h>
int f(int m) {
	int sum=0;
	for(int i=1; i<m; i++) {
		if(m%i==0)
			sum+=i;
	}
	return sum;
}
int main() {
	int T;
	scanf("%d",&T);
	while(T--) {
		int a,b;
		scanf("%d %d",&a,&b);
		int fa=f(a),fb=f(b);
		if(fa==b||fb==a)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Problem link: HDU 2040 Amicable Numbers

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...