zoukankan      html  css  js  c++  java
  • Semi-prime H-numbers

    题目描述形如4n+1的数被称为“H数”,乘法在“H数”集合内为封闭的。因数只有1和本身的数叫“H素数”(不包括1),其余叫“H合数”。一个“H合成数”能且只能分解为两个“H素数”。求0·h内的“H合成数”个数。

    分析:可以根据同余理论筛素数。

      如果一个数x为“H素数”,5*x+4*x*j一定是“H合数”

      标记合数,找到素数就把它的倍数处理打上合数标记。

      最后要统计一下。

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #include<cmath>
    #include<string>
    using namespace std;
    #define M 1000001+16
    bool he[M],hech[M];
    int su[M],ans[M];
    long long tot;
    int main()
    {
        int i,j;
        for( i=5;i<M;i+=4)
        {
            if(he[i])    continue;//合数跳过 
            su[++tot]=i;
            for(j=i*5;j<M;j+=i*4)//素数的推论,找合数 
                he[j]=true; 
        }
        for(i=1;i<=tot;i++)
            for(j=1;j<=i&&su[i]*su[j]<M;j++)
                hech[su[i]*su[j]]=true;
        for(i=1;i<M;i++)
            ans[i]=ans[i-1]+hech[i];
        int h;
        scanf("%d",&h);
        while(h)
        {
            printf("%d %d
    ",h,ans[h]);
            scanf("%d",&h);
        } 
        return 0;
    }
  • 相关阅读:
    project
    类欧几里得算法
    还不熟悉的内容
    Hall定理
    FWT学习笔记
    最小树形图
    BZOJ 3027 [Ceoi2004]Sweet
    多项式除法
    VUE 计算属性和侦听器
    VUE 模板语法
  • 原文地址:https://www.cnblogs.com/CLGYPYJ/p/6899545.html
Copyright © 2011-2022 走看看