USACO2010牛友

Bessie and all the other cows have an RFID serial number tag in their ear so FJ can mechanically tally them. Many cows have a ‘cowpal’ whose serial number is equal to the sum of the divisors (that are not the number itself) of their own serial number. Some cows don’t have a cowpal because no cow’s serial number matches their divisor sum.
Some cows have a superpal. Cows are superpals when their serial numbers make each of them a pal of the other. Cows that are superpals of themselves are shunned; do not consider them!
Given a serial number S (6 <= S <= 18,000), find the first cow with serial number at least S who has a super pal.
By way of example, consider serial number 220 whose divisors are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, and 110. Their sum is 284. Similarly, the divisors of 284 are 1, 2, 4, 71, and 142. Their sum is 220.

Bessie和其他的所有奶牛的耳朵上都戴有一个射频识别(RFID,不能使用英文缩略词)序列号码牌。因此FJ可以机械化地计算他们的数量。很多奶牛有一个“牛友”:一只奶牛的牛友的序列号刚好等于奶牛自己的序列号的所有约数之和。在这里,一个数的“约数”不包括这个数本身。因为一些奶牛的号码约数和大于其他任何奶牛的号码,所以这些奶牛没有牛友。
一些奶牛有一个“非常好友”。当两个奶牛互为“牛友”时,他们就是一对“非常好友”。注意在这道题中,忽略那些自己是自己的“非常好友”的情况。
给定一个序列号S (6 <= S <= 18,000),找到序列号不小于S的第一只有“非常好友”的奶牛。
比如说,考虑序列号220,它的约数是1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 和110。和是284。类似的,284的约数是1, 2, 4, 71, 和142。他们的和是220

枚举啊枚举

#include <bits/stdc++.h> 
using namespace std; 

template <class T> 
inline void read(T &s) {
	s = 0; T w = 1, ch = getchar(); 
	while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); }
	while (isdigit(ch)) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	s *= w; 
}

int n; 

int get(int x) {
	int sum = 0; 
	for (int i = 2; i * i <= x; ++i) {
		if (x % i == 0) {
			sum += x / i; 
			sum += i; 
		}
	}
	return sum + 1; 
}

int main() {
	read(n); 
	for (int i = n; i; ++i) {
		int x = get(i); 
		int y = get(x); 
		if (i == y && x != y) {
			printf("%d %d\n", i, x); 
			return 0; 
		}
	}
	return 0; 
}
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BIGBIGPPT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值