UVA 10539 Almost Prime Numbers( 素数因子)
来源:互联网 发布:平面图用什么软件画 编辑:程序博客网 时间:2024/05/29 02:43
Almost prime numbers are the non-prime numbers which are divisible by only a single prime number. In this problem your job is to write a program which finds out the number of almost prime numbers within a certain range.
Input
First line of the input file contains an integer N (N <= 600) which indicates how many sets of inputs are there. Each of the next N lines make a single set of input. Each set contains two integer numbers low and high (0 < low <= high < 1012).
Output
For each line of input except the first line you should produce one line of output. This line contains a single integer, which indicates how many almost prime numbers are within the range (inclusive) low…high.
31 101 201 5
341
代码:
#include<iostream>#include<string>#include<cstdio>#include<algorithm>#include<cmath>#include<iomanip>#include<queue>#include<cstring>#include<map>using namespace std;#define M 1000005typedef long long ll;int n,c;ll low,high;bool vis[M];ll prime[M/10];void init(){ int m=sqrt(1000000+0.5); int i,j; c=0; for(i=2;i<=m;i++) { if(!vis[i]) { for(j=i*i;j<=1000000;j+=i) { vis[j]=true; } } } for(i=2;i<=1000000;i++) { if(!vis[i]) prime[c++]=(ll)i; }}int main(){ int i; ll j; init(); scanf("%d",&n); while(n--) { scanf("%lld%lld",&low,&high); ll ans=0; for(i=0;i<c;i++) { if(prime[i]>high) break; for(j=prime[i]*prime[i];j<=high;j*=prime[i]) { if(j>=low) { ans++; } } } cout<<ans<<endl; } return 0;}
阅读全文
0 0
- UVA 10539 Almost Prime Numbers( 素数因子)
- UVa 10539 - Almost Prime Numbers(筛选求素数)
- UVa 10539 - Almost Prime Numbers
- UVa 10539 - Almost Prime Numbers
- UVa 10539 - Almost Prime Numbers
- UVa 10539 - Almost Prime Numbers
- UVA 10539 Almost Prime Numbers
- Uva 10539 Almost Prime Numbers
- UVa 10539 Almost Prime Numbers
- UVA 10539 Almost Prime Numbers
- Almost Prime Numbers UVA
- Almost Prime Numbers UVA
- UVA 10539 - Almost Prime Numbers(数论)
- uva 10539 - Almost Prime Numbers(数论)
- uva 10539——Almost Prime Numbers
- UVA 10539(p343)----Almost Prime Numbers
- 10539 - Almost Prime Numbers
- UVA 10539 Almost Prime
- TWITTER SDE 电面面经
- wamp的Apache无法启动
- NRF51822之发射功率
- 11月6日学习心得
- 一个基于DialogFragment的图片浏览器
- UVA 10539 Almost Prime Numbers( 素数因子)
- C和指针之函数之归以字符形式按顺序打印数字的每位数字(递归和非递归)
- POJ2135:Farm Tour
- List集合学习
- ImageLoader三级缓存
- MyEclipse 查看 [Deployment Assembly] 出现 [the currently displayed page contains invalid values]
- Ubuntu16.04+hadoop2.8.2搭建伪分布式
- int和Integer解析
- centos 7 rhel7怎么用mail发送邮件 到163 外部邮箱