Almost Prime Numbers UVA

Posted towboa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Almost Prime Numbers UVA相关的知识,希望对你有一定的参考价值。

 

 

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std ; 

 const int M =1e6+33;
 #define int long long
 int b[M],c[M],tot;
 int s[M] ;
 
 void init(int top)
     memset(b,1,sizeof b); b[1]=0;
     int i,j;
     for(i=2;i<=top;i++)
         if(b[i]) c[++tot]=i;
         
        for(j=1;j<=tot&&i*c[j]<=top;j++)
             b[i*c[j]]=0;
             if(i%c[j]==0) break;
         
     
 
 
 signed main()
 	init(1e6); 
 	int x,y,tes ;
 	cin>>tes;
 	while(tes--)
 		int ans =0;
 		cin>>x>>y; 
 		
 		for(int i=1;i<=tot;i++)
 			for(int j=c[i]*c[i];j<=y;j*=c[i])
 				if(j>=x) ans++;
 		cout<<ans<<\'\\n\'; 
 	
 
 
 
 

 

UVA11987--Almost Union-Find

zz:https://blog.csdn.net/scut_pein/article/details/8660719?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

#include <iostream>
#include <cstdio>
using namespace std;
#define maxn 200018
int father[maxn],idx[maxn],num[maxn];//num来多少个,idx才存
long long int sum[maxn];
int n,m,cnt;
int find(int x)
{
    if(x==father[x])return x;
    return find(father[x]);
}
void init()
{
    for(int i=1;i<=n;i++)
    {
        father[i]=idx[i]=sum[i]=i;
        num[i]=1;
    }
    cnt=n;
}
void Union(int p,int q)
{
    int pp=find(idx[p]),qq=find(idx[q]);
    father[pp]=qq;
    num[qq]+=num[pp];
    sum[qq]+=sum[pp];
}
void Delete(int p)
{
    int pp=idx[p];
    sum[find(pp)]-=p;
    num[find(pp)]--;
    idx[p]=++cnt;sum[idx[p]]=p;num[idx[p]]=1;father[idx[p]]=idx[p];
}
int main()
{
    while(scanf("%d%d",&n,&m)==2)
    {
        init();
        int ope,p,q;
        for(int i=1;i<=m;i++)
        {
            scanf("%d",&ope);
            if(ope==1)
            {
                scanf("%d%d",&p,&q);
                if(find(idx[p])==find(idx[q]))continue;
                else Union(p,q);
            }
            else if(ope==2)
            {
                scanf("%d%d",&p,&q);
                if(find(idx[p])!=find(idx[q]))
                {
                    Delete(p);
                    Union(p,q);
                }
            }
            else 
            {
                int u;
                scanf("%d",&u);
                int fuck=find(idx[u]);
                printf("%d %lld
",num[fuck],sum[fuck]);//这里我用I64d既然WA。。。
            }
        }
    }
    return 0;
}
————————————————
版权声明:本文为CSDN博主「SCUT_Pein」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/scut_pein/article/details/8660719

 

以上是关于Almost Prime Numbers UVA的主要内容,如果未能解决你的问题,请参考以下文章

UVA 11105 Semi-prime H-numbers

UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)

UVa 11105 semi-prime H-numbers

[UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)

Sum of Consecutive Prime Numbers UVA3399 C

UVA - 11987 Almost Union-Find[并查集 删除]