sicily 1009. Mersenne Composite N

水题

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int p[14] = {11,13,17,19,23,29,31,37,41,43,47,53,59,61};
int main(int argc, char const *argv[])
{
  int n;
  cin >> n;
  for(int i = 0; i < 14; i++)
  {
    if(p[i] < n)
    {
       vector<long long>v;
       long long g = pow(2.0,p[i]) - 1;
       long long temp = g;
       long long j = 3;
       while(j*j <= g)
       {
        if(g % j == 0)
        {
          g /= j;
          v.push_back(j);
        }
        else j+=2;
       }
       if(g != 1&&!v.empty())
        v.push_back(g);
      if(!v.empty())
      {
        for(int k = 0; k < v.size(); k++)
        {
          if(k != v.size() - 1)
             cout << v[k] << " * ";
           else
            cout << v[k] << " ";
        }
      
      cout << "= " << temp << " = ( 2 ^ " << p[i] << " ) - 1" << endl;
      }
    }
  }
  return 0;
}                                 


阅读更多
上一篇不是技术牛人,如何拿到国内IT巨头的Offer
下一篇数据结构知识点总结整理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭