zoukankan      html  css  js  c++  java
  • 超级幂 (Super Power,UVa 11752)

     1 #include <iostream>
     2 #include <string.h>
     3 #include <string>
     4 #include <fstream>
     5 #include <algorithm>
     6 #include <stdio.h>
     7 #include <vector>
     8 #include <queue>
     9 #include <set>
    10 #include <cmath>
    11 using namespace std;
    12 const double eps = 1e-8;
    13 const int INF=0x7fffffff;
    14 unsigned long long uINF = ~0LL;
    15 #define MAXN 10000007
    16 typedef unsigned long long LL;
    17 LL vis[MAXN];
    18 LL prime[MAXN];
    19 
    20 void sieve(LL n)
    21 {
    22     LL m=(LL)sqrt(n+0.5);
    23     memset(vis,0,sizeof(vis));
    24     for(LL i=2;i<=m;i++)if(!vis[i])
    25     for(LL j=i*i;j<=n;j+=i)vis[j]=1;
    26 }
    27 
    28 LL gen_prime(LL n)
    29 {
    30     sieve(n);
    31     LL c=0;
    32     for(LL i=2;i<=n;i++)if(!vis[i])
    33         prime[c++]=i;
    34     return c;
    35 }
    36 
    37 LL gcd(LL a,LL b)
    38 {
    39     return b==0?a:gcd(b,a%b);
    40 }
    41 
    42 set<LL> ans;
    43 int main()
    44 {
    45     LL temp=uINF;
    46     LL pn=gen_prime(77);
    47     LL cn=0;
    48     bool comp[64]={0};
    49     LL tempn=0;
    50     for(LL i=2;i<64;i++)
    51     if(i<prime[tempn])comp[i]=1;
    52     else tempn++;
    53     //for(LL i=0;i<64;i++)if(comp[i])cout<<i<<' ';system("pause");
    54     ans.insert(1);
    55     for(LL i=2;i<=65536;i++)
    56     {
    57         LL a=i*i*i,j=3;
    58         while(a<=uINF/i)
    59         {
    60             a*=i;
    61             j++;
    62             if(comp[j])ans.insert(a);
    63 
    64         }
    65 
    66     }
    67     for(set<LL>::iterator it=ans.begin();it!=ans.end();it++)
    68     {if(*it)cout<<*it<<endl;}
    69 
    70     return 0;
    71 }

    枚举65536以内数的合数幂

  • 相关阅读:
    操作系统---学习笔记00
    操作系统---学习笔记0
    2015/07/16入园啦!
    1-1 console的用法
    2.3 js基础--DOM
    1.2 js基础
    1.1 js基础
    信息收集(1)
    Android概述
    从一次失败的比赛经历引发的思考
  • 原文地址:https://www.cnblogs.com/TO-Asia/p/3204701.html
Copyright © 2011-2022 走看看