| 比赛 | 
    20101101 | 
    评测结果 | 
    TAATAAAAEE | 
    | 题目名称 | 
    整数合并 | 
    最终得分 | 
    60 | 
    | 用户昵称 | 
    .Xmz | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2010-11-01 20:34:53 | 
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;
bool y[100001];
int su[10001],a,b,p;
struct node
{
	node *f;
	node *findfu()
	{
		if (f) return f->findfu();
		else return this;
	}
	
	void uni(node *p)
	{
		findfu()->f=p->findfu();
	}
}P[100001];
int sn;
int main()
{
	freopen("setb.in","r",stdin);
	freopen("setb.out","w",stdout);
	scanf("%d%d%d",&a,&b,&p);
	for (int i=2;i<=b;i++)
	{
		if (!y[i])
		{
			if (i>=p) su[++sn]=i;
			for (int j=i;j*i<=b;j++) y[j*i]=true;
		}
	}
	int ans=b-a+1;
	for (int i=1;i<=sn;i++)
	{
		int now=su[i];
		int t=0;
		for (int i=max(now,a);i<=b;i++)
		{
			if (!t)
			{
				if (i % now==0) t=i;
			}
			else
			{
				if (i % now==0)
				{
					if (P[i].findfu()!=P+t)
					{
						ans--;
						P[i].uni(P+t);
					}
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}