• HDU2441 ACM(Array Complicated Manipulation)


    ACM(Array Complicated Manipulation)

    Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 513    Accepted Submission(s): 104


    Problem Description
    Given an infinite array of integers 2,3,.... Now do some operations on it.

    The operation is to choose a minimum number from the array which is never been chosen, then change the status of its multiples excluding itself, i.e remove the multiples of the chosen number if they are in the array , otherwise add it to the array.keep the order after change.

    For instance, the first step, choose number 2, change the status of 4, 6, 8, 10... They are all removed from the array. The second step, choose 3, change the status of 6, 9, 12, 15...

    Pay attention: 9 and 15 are removed from the array while 6 and 12 are added to the array.
     
    Input
    Every line contains an integer n. The zero value for n indicates the end of input.
     
    Output
    Print "yes" or "no" according whether n is in the array.

    Sample Input
    2
    30
    90
    0
     
    Sample Output
    yes
    yes
    no
    Hint
    The number n never has a prime factor greater than 13000000, but n may be extremely large.
     
    Source
     
    打表找规律,将x质因数分解,假设x=prime1^k1 + prime2^k2 + ...,如果存在某个ki>=2,则输出no,否则输出yes。。。这么复杂的规律不知道网上的大神们是怎么发现的,至于严格证明我也不想看了=_=,主要是复习下筛选法打素数表,另外kuangbin神的大数模板真好用~
    /*
    ID: LinKArftc
    PROG: 2441.cpp
    LANG: C++
    */
    
    #include <map>
    #include <set>
    #include <cmath>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <utility>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define eps 1e-8
    #define randin srand((unsigned int)time(NULL))
    #define input freopen("input.txt","r",stdin)
    #define debug(s) cout << "s = " << s << endl;
    #define outstars cout << "*************" << endl;
    const double PI = acos(-1.0);
    const double e = exp(1.0);
    const int inf = 0x3f3f3f3f;
    const int INF = 0x7fffffff;
    typedef long long ll;
    
    #define DLEN 4
    #define MAXN 9999
    const int maxn = 66000;
    int num[maxn];
    int prime[maxn];
    int cnt;
    char str[1000];
    
    void init() {
        cnt = 0;
        memset(num, -1, sizeof(num));
        for (int i = 2; i <= (maxn >> 1); i ++) {
            for (int j = (i << 2); j <= maxn; j += i) num[j] = 0;
        }
        for (int i = 2; i <= maxn; i ++) {
            if (num[i]) prime[cnt ++] = i;
        }
    }
    
    class BigNum {
        private:
            int a[1000];
            int len;
        public:
            BigNum() { len = 1; memset(a, 0, sizeof(a)); }
            BigNum(const char*);
            BigNum(const BigNum &);
            BigNum &operator=(const BigNum &);
            BigNum operator+(const BigNum &) const;
            BigNum operator-(const BigNum &) const;
            BigNum operator*(const BigNum &) const;
            BigNum operator/(const int &) const;
            int operator%(const int &) const;
            void print();
    };
    
    BigNum::BigNum(const char*s) {
        int t, k, index, L, i;
        memset(a, 0, sizeof(a));
        L = strlen(s);
        len = L / DLEN;
        if (L % DLEN) len ++;
        index = 0;
        for (i = L - 1; i >= 0; i -= DLEN) {
            t = 0;
            k = i - DLEN + 1;
            if (k < 0) k = 0;
            for (int j = k; j <= i; j ++) t = t * 10 + s[j] - '0';
            a[index ++] = t;
        }
    }
    
    BigNum::BigNum(const BigNum &T):len(T.len) {
        int i;
        memset(a, 0, sizeof(a));
        for (i = 0; i < len; i ++) a[i] = T.a[i];
    }
    
    BigNum & BigNum::operator=(const BigNum &n) {
        int i;
        len = n.len;
        memset(a, 0, sizeof(a));
        for (i = 0; i < len; i ++) a[i] = n.a[i];
        return *this;
    }
    
    BigNum BigNum::operator/(const int &b) const {
        BigNum ret;
        int i, down = 0;
        for (int i = len - 1; i >= 0; i --) {
            ret.a[i] = (a[i] + down * (MAXN + 1)) / b;
            down = a[i] + down * (MAXN + 1) - ret.a[i] * b;
        }
        ret.len = len;
        while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len --;
        return ret;
    }
    
    int BigNum::operator%(const int &b) const {
        int i, d = 0;
        for (int i = len - 1; i >= 0; i --) d = ((d * (MAXN + 1)) % b + a[i]) % b;
        return d;
    }
    
    void BigNum::print() {
        int i;
        printf("%d", a[len-1]);
        for (int i = len - 2; i >= 0; i --) printf("%04d", a[i]);
        printf("
    ");
    }
    
    int main() {
        init();
        while (~scanf("%s", str)) {
            if (str[0] == '0') break;
            if (strlen(str) == 1 && str[0] == '1') {
                printf("no
    ");
                continue;
            }
            BigNum n = BigNum(str);
            int count;
            for (int i = 0; i < cnt; i ++) {
                count = 0;
                BigNum tmp = n;
                while (tmp % prime[i] == 0) {
                    count ++;
                    tmp = tmp / prime[i];
                    if (count >= 2) break;
                }
                if (count >= 2) break;
            }
            if (count >= 2) printf("no
    ");
            else printf("yes
    ");
        }
    
        return 0;
    }
     
     
  • 相关阅读:
    C# Nest客户端查询es字段为空的语句
    Nuget 包还原成功,但引用异常
    ES7.2 安装问题
    elasticsearch 子节点有Unassigned Shards处理方法 和 failed to obtain in-memory shard lock
    rabbitmq修改日志级别
    C# NEST terms
    ES create index template
    Servicestack + Exceptionless本地部署
    live-server的使用
    处理cnpm控制台运行无反应(干瞪眼 就是不动)
  • 原文地址:https://www.cnblogs.com/LinKArftc/p/4902658.html
Copyright © 2020-2023  润新知