梅森素数,给定k,求出所有素数n<=k,且满足2^n-1不是梅森素数的数,并且将它们分解
#include <cmath>
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define N 9
int array[N] = {11,23,29,37,41,43,47,53,59};
void calculate(int a)
{
vector<long long> result;
result.clear();
long long biginteger = (long long)pow(2.0,a) - 1;
long long temper = biginteger;
for(long long i = 3;i * i <= biginteger;i += 2)
{
if(biginteger % i == 0)
{
biginteger = biginteger / i;
result.push_back(i);
}
}
if(biginteger != 1)
result.push_back(biginteger);
if(!result.empty())
{
for(int j = 0;j < result.size();j++)
{
if(j == result.size() - 1)
{
cout << result[j] << " ";
}
else
{
cout << result[j] << " * ";
}
}
cout << "= " << temper << " = " << "( 2 ^ " << a << " ) - 1" << endl;
result.clear();
}
}
int main()
{
int n;
scanf("%d",&n);
for(int i = 0;i < N;i++)
{
if(array[i] < n)
{
calculate(array[i]);
}
else
break;
}
return 0;
}