题意:

你现在来到了一个所有的数都模4余1的世界,也就是除了这种数没有其他的数了。

然而素数的定义依然没变,如果一个数不能写成两个非1数字的乘积,则它是素数。

比如,在这里5就变成了最小的素数。

两个素数相乘得到一个半素数,比如5×5 = 25就是最小的半素数。

求1~h之间有多少个半素数。

分析:

虽然是要求[1, h]之间半素数的个数,但向往常筛普通素数一样先把所有的4k+1的素数筛出来。

然后二重循环枚举半素数,最后统计区间内[1, h]的半素数个数SUMh

 #include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; const int maxn = + ;
bool vis[maxn + ];
int prime[], cnt, sum[maxn + ]; void Init()
{
int m = sqrt(maxn + 0.5);
for(int i = ; i <= m; i += ) if(!vis[i])
for(int j = i * i; j <= maxn; j += i)
vis[j] = true;//H-素数筛选 for(int i = ; i <= maxn; i += ) if(!vis[i]) prime[cnt++] = i; memset(vis, false, sizeof(vis));
for(int i = ; i < cnt; i++)
{//筛选H-半素数
for(int j = i; j < cnt; j++)
{
long long k = (long long)prime[i] * (long long) prime[j];
if(k > (long long)maxn) break;
vis[k] = true;
}
} for(int i = ; i <= maxn; i++) sum[i] = sum[i-] + vis[i];
} int main()
{
freopen("in.txt", "r", stdin);
Init();
int n;
while(scanf("%d", &n) == && n) printf("%d %d\n", n, sum[n]); return ;
}

代码君

UVa 11105 (筛法) Semi-prime H-numbers的更多相关文章

  1. 紫书 习题 10-17 UVa 11105 (筛法)

    类似于素数筛的思想去做,不然暴力会超时而且还要判重 #include<cstdio> #include<cstring> #include<vector> #def ...

  2. uva 11105 - Semi-prime H-numbers(数论)

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36644069 option=com_onli ...

  3. (全国多校重现赛一) H Numbers

    zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...

  4. UVA 11105 Semi-prime H-numbers

    https://vjudge.net/problem/UVA-11105 筛法 #include<cstdio> #include<cstring> #define N 100 ...

  5. UVA - 11105 Semi-prime H-numbers(H-半素数)

    题意:所有形如4n+1(n为非负整数)的数叫H数.定义1是唯一的单位H数,H素数是指本身不是1,且不能写成两个不是1的H数的乘积.H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同 ...

  6. UVA它11292 - Dragon of Loowater

    Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...

  7. POJ 3292 Semi-prime H-numbers (素数筛法变形)

    题意:题目比较容易混淆,要搞清楚一点,这里面所有的定义都是在4×k+1(k>=0)这个封闭的集合而言的,不要跟我们常用的自然数集混淆. 题目要求我们计算 H-semi-primes, H-sem ...

  8. Prime Matrix(暴力出奇迹)

    Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...

  9. 河南省第十届省赛 Binary to Prime

    题目描述: To facilitate the analysis of  a DNA sequence,  a DNA sequence is represented by a binary  num ...

随机推荐

  1. Regex.Match 方法

    Regex.Match 方法 在输入字符串中搜索正则表达式的匹配项,并将精确结果作为单个 Match 对象返回. 重载列表      (1) 在指定的输入字符串中搜索 Regex 构造函数中指定的正则 ...

  2. html5游戏引擎-Pharse.js学习笔记(一)

    1.前言 前几天随着flappy bird这样的小游戏的火爆,使我这种也曾了解过html5技术的js业余爱好者也开始关注游戏开发.研究过两个个比较成熟的html5游戏引擎,感觉用引擎还是要方便一些.所 ...

  3. c# XAML

    http://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/hh465340.aspx 如果你选择在 Microsoft Visual Basi ...

  4. Apache Spark探秘:三种分布式部署方式比较

    转自:链接地址: http://dongxicheng.org/framework-on-yarn/apache-spark-comparing-three-deploying-ways/     目 ...

  5. Problem 1007 幸运数 线段树成段更新

    题目链接: 题目 Problem 1007 幸运数 Time Limit: 2000 mSec Memory Limit : 131072 KB 问题描述 皮特的幸运数是2和5.只由幸运数字2和5组成 ...

  6. 【转】2-SAT题集

    转自:http://blog.csdn.net/shahdza/article/details/7779369 [HDU]3062 Party1824 Let's go home3622 Bomb G ...

  7. oracle——表修改语句集合

     alter table table_name modify column_name default 0; 

  8. 解决eclipse打开报错:failed to create the java virtual ma

    在Eclipse安装目录下找到:eclipse.ini 将如下参数改为: --launcher.XXMaxPermSize 128M ------------------------------- 说 ...

  9. 【系统Configmachine.config与自己的应用程序的App.config/Web.Config配置节点重复】解决方法

    自己的应用程序的App.config或Web.Config文件中与系统的C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Configmachine.co ...

  10. php浮点数精确运算

    php浮点数精确运算 Php: BCMath bc是Binary Calculator的缩写.bc*函数的参数都是操作数加上一个可选的 [int scale],比如string bcadd(strin ...