UVa Problem 10006 Carmichael Numbers (Carmichael 数)

// Carmichael Numbers (Carmichael 数)
// PC/UVa IDs: 110702/10006, Popularity: A, Success rate: average Level: 2
// Verdict: Accepted
// Submission Date: 2011-06-10
// UVa Run Time: 0.336s
//
// 版权所有(C)2011,邱秋。metaphysis # yeah dot net
//
// 此题关键是应用求模公式 x^y mod n = (x mod n)^y mod n。这里用到了预先计算给定范围内所有
// Carmichael 数的方法,因为在这区间里的数并不多!如果使用求模的方式,注意使用
// (x mod n) ^ y mod n = ((x mod n) ^ (y / 2) mod n) * ((x mod n) ^ (y / 2)
//  mod n) * ((x mod n) ^ (y % 2) mod n) mod n,减少计算时间,否则容易TLE。

#include <iostream>
#include <cmath>

using namespace std;

#define CAPACITY 15

void print(int n, bool normal)
{
	if (normal)
		cout << n << " is normal." << endl;
	else
		cout << "The number " << n << " is a Carmichael number." << endl;
}

int main(int ac, char *av[])
{
	int n;
	int array[CAPACITY] =
		{ 561, 1105, 1729, 2465, 2821, 6601, 8911, 10585, 15841, 29341,
			41041, 46657, 52633, 62745, 63973 };

	while (cin >> n, n)
	{
		bool normal = true;
		for (int c = 0; c < CAPACITY; c++)
			if (array[c] == n)
			{
				normal = false;
				break;
			}

		print(n, normal);
	}

	return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值