int isprime(unsigned long n) //判断素数的程序
{
unsigned long i
for(i = 蚂兄2 i < n i++)
{
if(n % i == 0)
break
}
if(i == n)
return 1
else
return 0
}
unsigned long power(unsigned long x, unsigned long n)//求x的n次幂
{
unsigned long s = 1,i
for(i = 0 i < n i++)
{
s = s * x
}
return s
}
int main()
{
unsigned long a,s,i
for(i = 2 i <= 32 i++)
{
s = power(2,i)-1
if(isprime(i) && isprime(s))
printf("2^%lu-1 = %lu\n",i,s)
正物察举茄}
}
// 计算梅森数的位数的C++源代码如下#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std
int main()
{
int p
cout<<"Please input a prime number p:"
cin>>p
cout<<"M"<<p<<" 伍前仔is a "<<int(p*log10(2)+1)<腔汪<"-digit number.\n"悔早
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)