toj3259[Mysterious Numbers]埃式筛法
2014-08-05 09:10
281 查看
3259.
Mysterious Number
Time Limit: 1.0 Seconds Memory Limit:
65536K
Total Runs: 1267 Accepted Runs:
400
Mysterious Number refers to a number which can be divisible by the number of distinct factors that it has. For instance, 1 (1 factor), 12 (6 factors) and 9 (3 factors) are Mysterious Numbers, but 7(2 factors) or 16 (5 factors) are not.
Given two integers low and high, please calculate the number of Mysterious Numbers between
low and high, inclusive.
low ≤ high ≤ 1,000,000
Author: WTommy
Source: TJU Team Selection
Contest 2009 (4)
Submit List Runs
Forum Statistics
题目大意是有一种数称为"神秘数", 特征是可以被自己约数的个数整除.比如9有1,3,9三个约数,约数个数为3,而9又能被3整除,所以9是神秘数.又如12有6个约数,12可以被6整除,那12也是神秘数.7有2个约数,但7不能被2整除,所以不是神秘数.
输入给出上下限low, high让你求[low,high]区间有多少个"神秘数".
我靠, 这题搁以前我一定枚举.但是.....呃.....呃..
好吧啊,这题就是埃式筛法.
两个循环可以求出1~100万所有数的约数个数.然后可以dp加速一下.转移
dp[i] = {dp[i-1], i不是神秘数
{ dp[i-1]+1, i是神秘数
然后每次询问low,high.输出dp[high] - dp[low-1]即可.
细节注意:0和1的约数个数处理.
Mysterious Number
Time Limit: 1.0 Seconds Memory Limit:
65536K
Total Runs: 1267 Accepted Runs:
400
Mysterious Number refers to a number which can be divisible by the number of distinct factors that it has. For instance, 1 (1 factor), 12 (6 factors) and 9 (3 factors) are Mysterious Numbers, but 7(2 factors) or 16 (5 factors) are not.
Given two integers low and high, please calculate the number of Mysterious Numbers between
low and high, inclusive.
Input
For each test case, there are two integers low and high in one line separated by spaces.1 ≤low ≤ high ≤ 1,000,000
Output
Print out the number of Mysterious Numbers between low and high, inclusive.Sample Input
1 10 10 15
Sample Output
4 1
Author: WTommy
Source: TJU Team Selection
Contest 2009 (4)
Submit List Runs
Forum Statistics
题目大意是有一种数称为"神秘数", 特征是可以被自己约数的个数整除.比如9有1,3,9三个约数,约数个数为3,而9又能被3整除,所以9是神秘数.又如12有6个约数,12可以被6整除,那12也是神秘数.7有2个约数,但7不能被2整除,所以不是神秘数.
输入给出上下限low, high让你求[low,high]区间有多少个"神秘数".
我靠, 这题搁以前我一定枚举.但是.....呃.....呃..
好吧啊,这题就是埃式筛法.
两个循环可以求出1~100万所有数的约数个数.然后可以dp加速一下.转移
dp[i] = {dp[i-1], i不是神秘数
{ dp[i-1]+1, i是神秘数
然后每次询问low,high.输出dp[high] - dp[low-1]即可.
细节注意:0和1的约数个数处理.
0'00.08" | 8672K |
#include <cstdio> #include <cmath> #include <algorithm> using namespace std; const int MAX = 1000000+1111; int a[MAX] = {0,1}; int dp[MAX] = {0}; int main() { fill(a+2, a+MAX, 2); int i, j; for (i = 2; i < (MAX>>1); ++i) for (j = 2; i * j < MAX; ++j) { ++a[i*j]; } //printf("%d\n", a[57896]); //57896 have 8 primes~ for (i = 1; i < MAX; ++i) { dp[i] = dp[i-1] + (i % a[i] ? 0 : 1); } int low, high; while (~scanf(" %d %d", &low, &high)) { printf("%d\n", dp[high] - dp[low-1]); } return 0; }
相关文章推荐
- 埃式筛法
- 埃式筛法
- TOJ 3259.Mysterious Number(埃式筛法)
- TOJ 3105.A Way To Find Primes(埃式筛法)
- 埃式筛法
- 【算法-简单数学问题】- 素数表的获取(简单方法和埃式筛法)
- 埃式筛法计算素数Python3(学了一阵儿了,第一次写.)
- 埃式筛法(素数筛) + 区间素数筛 + 应用
- 素数筛(埃式筛法/欧拉筛法)
- G-Prime Generator|埃式筛法
- (扩展)欧几里得算法、素性测试、埃式筛法、区间筛法、快速幂运算
- 埃式筛法——快速筛选n以内的素数
- TOJ 1868.Count the factors(埃式筛法)
- poj3126 埃式筛法+bfs
- 【埃式筛法】My pretty girl Noora CodeForces - 822D
- 埃式筛法模板及其改进
- Eratosthenes筛法的粗糙汇编源代码
- 筛法求素数
- 位数组实现用筛法(Sieve of Eratosthnes)计算素数
- 1089. Farey Sequence (欧拉函数+筛法)