UVa 11105 (筛法) Semi-prime H-numbers
题意:
你现在来到了一个所有的数都模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的更多相关文章
- 紫书 习题 10-17 UVa 11105 (筛法)
类似于素数筛的思想去做,不然暴力会超时而且还要判重 #include<cstdio> #include<cstring> #include<vector> #def ...
- uva 11105 - Semi-prime H-numbers(数论)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36644069 option=com_onli ...
- (全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...
- UVA 11105 Semi-prime H-numbers
https://vjudge.net/problem/UVA-11105 筛法 #include<cstdio> #include<cstring> #define N 100 ...
- UVA - 11105 Semi-prime H-numbers(H-半素数)
题意:所有形如4n+1(n为非负整数)的数叫H数.定义1是唯一的单位H数,H素数是指本身不是1,且不能写成两个不是1的H数的乘积.H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同 ...
- UVA它11292 - Dragon of Loowater
Problem C: The Dragon of Loowater Once upon a time, in the Kingdom of Loowater, a minor nuisance tur ...
- POJ 3292 Semi-prime H-numbers (素数筛法变形)
题意:题目比较容易混淆,要搞清楚一点,这里面所有的定义都是在4×k+1(k>=0)这个封闭的集合而言的,不要跟我们常用的自然数集混淆. 题目要求我们计算 H-semi-primes, H-sem ...
- Prime Matrix(暴力出奇迹)
Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...
- 河南省第十届省赛 Binary to Prime
题目描述: To facilitate the analysis of a DNA sequence, a DNA sequence is represented by a binary num ...
随机推荐
- 笔记本电脑连接wifi有时候会自动断网提示有限的访问权限解决办法
解决办法如下: [设备管理器],找到[网络适配器]第一项,右键属性
- request 路径随笔
1. 路劲可分为 绝对路径 和 相对路径 2. 绝对路径 (开头带"/") 前端: http://localhost:8080/myWebApp/user/login.jsp /m ...
- 使用maven多模块来构建系统时,spring初始化报错的问题
最近在实验maven结构的maven工程时,碰到一个问题,springbean总是初始化失败: Related cause: org.springframework.beans.factory.Uns ...
- Matlab中cell2mat的使用
binIndices是1*50的cell,每个cell是的1*n(n不定),那么cell2mat(binIndices)得到的是1*sum(cellfun(@length,binIndices))的行 ...
- vs-ps combination error
http://social.msdn.microsoft.com/Forums/en-US/5dfef3d9-edc1-4006-9e81-9d5326419df8/d3d10effect-compi ...
- Unity3D脚本中文系列教程(十四)
http://dong2008hong.blog.163.com/blog/static/469688272014032134394/ WWWFrom 类Unity3D脚本中文系列教程(十三)辅助类. ...
- hadoop倒排索引
1.前言 学习hadoop的童鞋,倒排索引这个算法还是挺重要的.这是以后展开工作的基础.首先,我们来认识下什么是倒拍索引: 倒排索引简单地就是:根据单词,返回它在哪个文件中出现过,而且频率是多少的结果 ...
- jquery cookie 用法
jquery cookie 用法 $.cookie("name","value","options") 当不设置options时,此coo ...
- cvc-elt.1: Cannot find the declaration of element---与spring 无关的schema 验证失败
晚上查了好久,都是spring 出这种问题的解决方式,终于查到为什么了. http://wakan.blog.51cto.com/59583/7218/ 转自这个人.. 多谢啦! 为了验证 XML 文 ...
- [GCJ]Password Attacker
https://code.google.com/codejam/contest/4214486/dashboard#s=p0 排列组合.DP递推式,如下代码.dp[m][n]表示长度为n的字符串里有m ...