zoukankan      html  css  js  c++  java
  • POJ

    http://poj.org/problem?id=2739

    题意:给1~10000的数字,求他有多少种连续质数分解,连续质数分解就是指连续的某些质数的和,比如2+3+5+7,3+5+7,这样的。

    预处理直接暴力。

    #include<algorithm>
    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<map>
    #include<set>
    #include<stack>
    #include<string>
    #include<queue>
    #include<vector>
    using namespace std;
    typedef long long ll;
    
    const int MAXN = 1e4;
    int p[MAXN + 5], ptop;
    bool np[MAXN + 5];
    
    void sieve(int n) {
        np[1] = 1;
        for(int i = 2; i <= n; ++i) {
            if(np[i])
                continue;
            else {
                p[++ptop] = i;
                for(int j = i + i; j <= n; j += i)
                    np[j] = 1;
            }
        }
    }
    
    int ans[MAXN + 5];
    
    int main() {
    #ifdef Yinku
        freopen("Yinku.in", "r", stdin);
    #endif // Yinku
        sieve(MAXN);
        for(int i = 1; i <= ptop; ++i) {
            int sum = 0;
            for(int j = i; j <= ptop; ++j) {
                sum += p[j];
                if(sum > MAXN)
                    break;
                ans[sum]++;
            }
        }
        int n;
        while(~scanf("%d", &n)) {
            if(n == 0)
                break;
            printf("%d
    ", ans[n]);
        }
    }
    
  • 相关阅读:
    数组
    习题
    JAVA 实战练习
    JAVA语言基础——类型转换
    JAVA 语言基础——运算符
    JAVA语法基础——数据类型
    09.22函数,三局两胜
    09.22 猜拳一次
    09.21,函数,累加求和
    09.21,枚举
  • 原文地址:https://www.cnblogs.com/Inko/p/11728527.html
Copyright © 2011-2022 走看看