[51nod-1441]士兵的数字游戏 题解
2017-09-24 15:40
399 查看
题目传送门
就是求每个素数因子的个数,然后用前缀和算出答案就好了。
在51nod上要用visual c++交,比c++快了三倍(不知道这是为什么)
就是求每个素数因子的个数,然后用前缀和算出答案就好了。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define rep(i,a,n) for (int i=a;i<=n;i++) #define per(i,a,n) for (int i=a;i>=n;i--) #define Clear(a,x) memset(a,x,sizeof(a)) #define ll long long #define INF 2000000000 #define eps 1e-8 #define db double using namespace std; int read(){ int x=0,f=1; char ch=getchar(); while (ch<'0'||ch>'9') f=ch=='-'?-1:f,ch=getchar(); while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; } const int maxn=5000005; int sum[maxn]; bool flag[maxn]; void init(){ int tmp,i,j; for (i=2;i<=maxn-5;i++) if (!flag[i]){ for (j=i;j<=maxn-5;j+=i){ tmp=j; while (tmp%i==0){ tmp/=i; sum[j]++; } flag[j]=1; } } rep(i,1,maxn-5) sum[i]+=sum[i-1]; } int main(){ int T=read(); int a,b; init(); while (T--){ a=read(),b=read(); printf("%d\n",sum[a]-sum[b]); } return 0; }
在51nod上要用visual c++交,比c++快了三倍(不知道这是为什么)
相关文章推荐
- 51nod 1441 士兵的数字游戏 (素数筛变形)
- 51nod 1441 士兵的数字游戏
- 51nod 1441 士兵的数字游戏【素数筛】
- 1441 士兵的数字游戏 51nod
- 51nod-1441 士兵的数字游戏
- 51Nod-1441-士兵的数字游戏
- 51nod 1441 士兵的数字游戏 (模拟线性筛)
- 51nod 1441:士兵的数字游戏
- 51nod 1441:士兵的数字游戏
- 1441 士兵的数字游戏
- 1441 士兵的数字游戏
- 1441 士兵的数字游戏
- 士兵的数字游戏
- 51nod1441 士兵的数字游戏 分解质因子
- 51nod1441 士兵的数字游戏
- 质数筛 51Nod1441 士兵的数字游戏
- 猜数字游戏
- 51nod 1387 移数字
- 51nod 1009 数字1的数量
- 51nod 1070 Bash游戏 V4(博弈——找规律)