标签:style blog http color get 2014
题意:给定4 * n + 1的集合,在这个集合基础上求这个集合的集合素数,然后求出这个集合中,由两个集合素数相乘得到的数有几个。
思路:先筛出集合素数,然后暴力一下两两组合有多少个即可。
代码:
#include <stdio.h> #include <string.h> const int N = 1000005; int vis[N], pri[N], pn = 0, n; int main() { for (int i = 5; i <= 1000001; i += 4) { if (vis[i]) continue; pri[pn++] = i; for (int j = i; j <= 1000001; j += i) { vis[j] = 1; } } while (~scanf("%d", &n) && n) { int ans = 0; memset(vis, 0, sizeof(vis)); for (int i = 0; i < pn; i++) { if (pri[i] * pri[i] > n) break; for (int j = i; j < pn; j++) { int mul = pri[i] * pri[j]; if (mul > n) break; if (vis[mul]) continue; ans++; vis[mul] = 1; } } printf("%d %d\n", n, ans); } return 0; }
UVA 11105 - Semi-prime H-numbers(数论),布布扣,bubuko.com
UVA 11105 - Semi-prime H-numbers(数论)
标签:style blog http color get 2014
原文地址:http://blog.csdn.net/accelerator_/article/details/35254961