记录编号 |
48525 |
评测结果 |
AAAAAAAAAA |
题目名称 |
整数合并 |
最终得分 |
100 |
用户昵称 |
Truth.Cirno |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.051 s |
提交时间 |
2012-11-05 21:22:43 |
内存使用 |
4.13 MiB |
显示代码纯文本
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <memory.h>
- #include <stack>
- using namespace std;
-
- int dad[100010],siz[100010];
- bool nosu[100010];
- stack<int> sta;
-
- int findroot(int ys)
- {
- while (dad[ys])
- {
- sta.push(ys);
- ys=dad[ys];
- }
- while (!sta.empty())
- {
- dad[sta.top()]=ys;
- sta.pop();
- }
- return(ys);
- }
-
- void combine(int a,int b)
- {
- a=findroot(a);
- b=findroot(b);
- if (a==b)
- return;
- if (siz[a]>siz[b])
- {
- siz[a]+=siz[b];
- dad[b]=a;
- }
- else
- {
- siz[b]+=siz[a];
- dad[a]=b;
- }
- }
-
- int main(void)
- {
- freopen("setb.in","r",stdin);
- freopen("setb.out","w",stdout);
- int i,j,a,b,p,total,temp;
- cin>>a>>b>>p;
- for (i=1;i<=b;i++)
- siz[i]=1;
- nosu[1]=true;
- for (i=2;i<=b;i++)
- {
- if (!nosu[i])
- {
- for (j=i<<1;j<=b;j+=i)
- {
- nosu[j]=true;
- if (i>=p)
- if (j>=a)
- combine(i,j);
- }
- }
- }
- total=0;
- memset(nosu,0,sizeof(nosu));//we can call "nosu" as "answer" now
- for (i=a;i<=b;i++)
- {
- temp=findroot(i);
- if (!nosu[temp])
- {
- total++;
- nosu[temp]=true;
- }
- }
- cout<<total<<endl;
- return(0);
- }