• The Super Powers UVA


    题意:

    求1~2^64-1之间所有的 至少是两个不同的正整数的幂的数  升序输出 

    一个数的合数次幂即为这样的数

    找出1~2^64-1中所有数的合数次幂 用set存起来(既能防止重复 又能升序) 最后输出就好了

    #include <iostream>
    #include <cstdio>
    #include <sstream>
    #include <cstring>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <climits>
    #define MOD 2018
    #define LL long long
    #define ULL unsigned long long
    #define Pair pair<int, int>
    #define mem(a, b) memset(a, b, sizeof(a))
    #define _  ios_base::sync_with_stdio(0),cin.tie(0)
    //freopen("1.txt", "r", stdin);
    using namespace std;
    const int maxn = 100010, INF = 0x7fffffff;
    LL vis[maxn];
    int ans;
    set<ULL> s;
    
    ULL power(ULL a, ULL b) {     //快速幂
        ULL res = 1;
        while(b)
        {
            if(b & 1) res = res * a;
            a = a * a;
            b >>= 1;
        }
        return res;
    }
    //ULL power(int a, int b)  //二分幂
    //{
    //    if(b == 0) return 1;
    //    ULL res = power(a, b/2);
    //    res *= res;
    //    if(b & 1) res *= a;
    //    return res;
    //}
    
    void init()
    {
        ans = 0;
        mem(vis, 0);
        for(int i=2; i<=64; i++)
            if(!vis[i])
            {
                for(LL j=(LL)i*i; j<=64; j+=i)
                   vis[j] = 1;
            }
    }
    
    int main()
    {
        init();
        s.insert(1);
    
        for(ULL i=2; i< (1<<16); i++)
        {
            double t=ceil(64.0/log(i)*log(2))-1;
    
            for(int j=4; j<=64; j++)
            {
                if(!vis[j])continue;
                if(j> t) break;
                ULL res = power(i, j);
                s.insert(res);
            }
        }
        for(set<ULL>::iterator it=s.begin(); it!=s.end(); it++)
            printf("%llu
    ",*it);
    
    
        return 0;
    }
    自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。
  • 相关阅读:
    【STL】queue容器
    【STL】stack容器
    【STL】deque容器
    【STL】迭代器
    【STL】vector容器
    【STL】string
    tensorflow学习012——tf.keras函数式API
    tensorflow学习010——优化函数、学习速率、反向传播算法、网络优化、超参数
    Tensorflow学习009——softmax多分类
    tensorflow学习008——逻辑回归实现
  • 原文地址:https://www.cnblogs.com/WTSRUVF/p/9319092.html
Copyright © 2020-2023  润新知