sicily 1009 Mersenne Composite N

//给一个数k,对小于k的素数,若2^k -1 的值是合数的话,求出它的质因子 

#include <stdlib.h>

#include <iostream>

#include <cmath>

using namespace std;

#define N 17

int array[N]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59};



void calculateResult(int a)

{

    long long bigNum=(long long)pow(2.0,a)-1;

    long long temp=bigNum;

    bool flag=true;

    bool isCom=false;

    long long i=2;

    for(;i*i<=bigNum;i++)

    {

        if(bigNum%i!=0)

        {

            continue;

        }

        else

        {

            if(flag)

            {

                cout<<i<<" ";

                flag=false;

            }

            else

            {

                cout<<"* "<<i<<" ";

            }

            bigNum/=i;

            isCom=true;

        }

    }

    if(isCom)

    {

        cout<<"* "<<bigNum<<" = "<<temp<<" = ( "<<2<<" ^ "<<a<<" ) - 1"<<endl;

    }

}



int main()

{

    int n;

    cin>>n;

    for(int i=0;i<N;i++)

    {

        if(array[i]<=n)

        {

             calculateResult(array[i]);

        }

        else

        {

            break;

        }

    }

    system("pause");

    return 0;



}

 

你可能感兴趣的:(com)