TOJ 3259.Mysterious Number(埃式筛法)
2016-08-12 17:53
141 查看
题目链接:http://acm.tju.edu.cn/toj/showp3259.html
3259. Mysterious Number
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1356 Accepted Runs: 435
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.
Author: WTommy
Source: TJU
Team Selection Contest 2009 (4)
Submit List
Runs Forum
Statistics
Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop
题意很好理解,所谓神秘数就是指一个数是否能够被它的约数整除。然后我就傻乎乎的枚举暴力来了一波,果不其然——超时。随后学习了一下大神的帖子,知道了一种算法叫:埃式筛法,关于埃式筛法具体的内容见博客:
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAX = 1000000+2;
int fac[MAX] = {0,1};
int main(){
int low,high,sum;
fill(fac+2,fac+MAX,2);
for (int i = 2; i < (MAX>>1); ++i)
for (int j = 2; i * j < MAX; ++j) {
++fac[i*j];
}
while(~scanf("%d%d",&low,&high)){
sum=0;
for(int i=low;i<=high;i++)
if(i%fac[i]==0)
sum++;
printf("%d\n",sum);
}
}
3259. Mysterious Number
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1356 Accepted Runs: 435
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,000Output
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
Tianjin University Online Judge v1.3.0
Maintance:G.D.Retop. Developer: SuperHacker, G.D.Retop
题意很好理解,所谓神秘数就是指一个数是否能够被它的约数整除。然后我就傻乎乎的枚举暴力来了一波,果不其然——超时。随后学习了一下大神的帖子,知道了一种算法叫:埃式筛法,关于埃式筛法具体的内容见博客:
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAX = 1000000+2;
int fac[MAX] = {0,1};
int main(){
int low,high,sum;
fill(fac+2,fac+MAX,2);
for (int i = 2; i < (MAX>>1); ++i)
for (int j = 2; i * j < MAX; ++j) {
++fac[i*j];
}
while(~scanf("%d%d",&low,&high)){
sum=0;
for(int i=low;i<=high;i++)
if(i%fac[i]==0)
sum++;
printf("%d\n",sum);
}
}
相关文章推荐
- TOJ 1868.Count the factors(埃式筛法)
- TOJ 3105.A Way To Find Primes(埃式筛法)
- toj3259[Mysterious Numbers]埃式筛法
- 埃式筛法
- G-Prime Generator|埃式筛法
- 埃式筛法
- 素数筛(埃式筛法/欧拉筛法)
- (扩展)欧几里得算法、素性测试、埃式筛法、区间筛法、快速幂运算
- poj3126 埃式筛法+bfs
- 埃式筛法计算素数Python3(学了一阵儿了,第一次写.)
- 埃式筛法
- 埃式筛法模板及其改进
- 【算法-简单数学问题】- 素数表的获取(简单方法和埃式筛法)
- 【埃式筛法】My pretty girl Noora CodeForces - 822D
- 埃式筛法——快速筛选n以内的素数
- 埃式筛法(素数筛) + 区间素数筛 + 应用
- TOJ 1032 等式问题 Accepted
- 筛法求小于等于整数n的所有质数
- toj 1721 Friends
- TOJ 1132 Knight Moves BFS求最短路径