UVA - 11105 Semi-prime H-numbers(H-半素数)
题意:所有形如4n+1(n为非负整数)的数叫H数。定义1是唯一的单位H数,H素数是指本身不是1,且不能写成两个不是1的H数的乘积。H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同)。输入一个H数h(h <=1000001),输出1~h之间有多少个H-半素数。
分析:
1、筛选法求H素数。
2、再枚举求H-半素数。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1e6 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<int> Hprime;
int vis[MAXN];
void init(){
for(int i = 5; i < MAXN; i += 4){
if(vis[i]) continue;
Hprime.push_back(i);
for(int j = i * 2; j < MAXN; j += i){
vis[j] = 1;
}
}
}
int solve(int n){
int ans = 0;
memset(vis, 0, sizeof vis);
int len = Hprime.size();
for(int i = 0; i < len; ++i){
if(Hprime[i] >= n) break;
if((LL)Hprime[i] * Hprime[i] > n) break;
for(int j = i; j < len; ++j){
if(Hprime[j] >= n) break;
LL tmp = (LL)Hprime[i] * Hprime[j];
if(tmp > n) break;
if(vis[tmp]) continue;
++ans;
vis[tmp] = 1;
}
}
return ans;
}
int main(){
init();
int n;
while(scanf("%d", &n) == 1){
if(!n) return 0;
printf("%d %d\n", n, solve(n));
}
return 0;
}
UVA - 11105 Semi-prime H-numbers(H-半素数)的更多相关文章
- UVA 10539 - Almost Prime Numbers(数论)
UVA 10539 - Almost Prime Numbers 题目链接 题意:给定一个区间,求这个区间中的Almost prime number,Almost prime number的定义为:仅 ...
- UVa 11105 (筛法) Semi-prime H-numbers
题意: 你现在来到了一个所有的数都模4余1的世界,也就是除了这种数没有其他的数了. 然而素数的定义依然没变,如果一个数不能写成两个非1数字的乘积,则它是素数. 比如,在这里5就变成了最小的素数. 两个 ...
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
UVA 1415 - Gauss Prime 题目链接 题意:给定a + bi,推断是否是高斯素数,i = sqrt(-2). 思路:普通的高斯素数i = sqrt(-1),推断方法为: 1.假设a或 ...
- uva 11105 - Semi-prime H-numbers(数论)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/36644069 option=com_onli ...
- uva 1415 - Gauss Prime(高斯素数)
题目链接:uva 1415 - Gauss Prime 题目大意:给出一个a,b,表示高斯数a+bi(i=−2‾‾‾√,推断该数是否为高斯素数. 解题思路: a = 0 时.肯定不是高斯素数 a != ...
- Sed命令n,N,d,D,p,P,h,H,g,G,x解析3
摘自:https://blog.csdn.net/WMSOK/article/details/78463199 Sed命令n,N,d,D,p,P,h,H,g,G,x解析 2017年11月06日 23: ...
- sed命令n,N,d,D,p,P,h,H,g,G,x解析2
摘自: https://blog.csdn.net/xiexingshishu/article/details/50514132 sed命令n,N,d,D,p,P,h,H,g,G,x解析 2016年0 ...
- oc 与 swift 之间的桥接文件 (ProjectNmae-Bridging-Header.h) (ProjectNmae-Swift.h)
oc 与 Swift 是2种不同的语言, oc代码只能写带oc文件里, Swift代码只能写在Swift文件里, 虽然2者不同语言, 但却能互相调用, 不过需要进行一下桥接, 就是下面的2个文件 (P ...
- jpeglib.h jerror.h No such file or directory 以及 SDL/SDL.h: 没有那个文件
1. error: jpeglib.h jerror.h No such file or directory 没有那个文件或目录 jpeg.cc:19:21:error: jpeglib.h: 没有那 ...
随机推荐
- SystemVerilog基本语法总结(下)
2018年IC设计企业笔试题解析-(验证方向) 1.请简述:定宽数组,动态数组,关联数组,队列四种数据类型的各自特点.解析:(1)定宽数组:其宽度在声明的时候就指定了,故其宽度在编译时就确定了.(2) ...
- android EditText中inputType的属性列表
android 1.5以后添加了软件虚拟键盘的功能,所以在输入提示中将会有对应的软键盘模式 android中inputType属性在EditText输入值时启动的虚拟键盘的风格有着重要的作用.这也大大 ...
- Day3-G - Task HDU4864
Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this ...
- Python 100 Days
Day 1 python的缺点 执行效率稍低,因此计算密集型任务可以由C/C++编写. 在开发时可以选择的框架太多(如Web框架就有100多个),有选择的地方就有错误. python解释器 官方的Py ...
- JAVA 集合 List 分组的两种方法
CSDN日报20170219--<程序员的沟通之痛> [技术直播]揭开人工智能神秘的面纱 程序员1月书讯 云端应用征文大赛,秀绝招,赢无人机! JAVA 集合 List 分组的两种方法 2 ...
- 几种编辑器的markdown-toc生成目录在github上的表现
Vscode vscode的markdown-toc插件的实现是比较好的, 目前发现的问题就只有在自动生成带链接目录的时候无法正确识别和生成一些特殊的字符. 例如: ▶ 这导致在标题中不能加入特殊字符 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 图片:缩略图功能
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Ubuntu基于Apache为自己的网站开启HTTPS
暂时放这里链接,之后整理 https://www.deanhan.cn/ubuntu-apache-https.html
- python2学习------基础语法2(函数)
1.函数 # 无参数函数 def loopTest2(): a=1; while a<40: print a; a=a+1; if a==35: continue; else: print 'o ...
- Python实现的远程登录windows系统功能示例
https://www.jb51.net/article/142326.htm 重点是这几本书要好好读读!: 更多关于Python相关内容感兴趣的读者可查看本站专题:<Python进程与线程操作 ...