• ZOJ 3435


    求(1,1,1)至(x,y,z)的互质个数。

    即求(0,0,0)到(x-1,y-1,z-1)互质个数。

    依然如上题那样做。但很慢。。。好像还有一个分块的思想,得学学。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #define N 1000005
    
    using namespace std;
    typedef long long LL;
    int mobi[N];
    bool vis[N];
    
    void initial(){
        int i,j;
        for(i=1;i<N;i++) mobi[i]=1,vis[i]=false; 
        for(i=2;i<N;i++) {
            if(vis[i]) continue;
            for(j=i;j<N;j+=i){
                vis[j]=true;
                if((j/i)%i==0){
                    mobi[j]=0; continue;
                }
                mobi[j]=-mobi[j];
            }
        }
    }
    
    int main(){
    	initial();
    	int t,x,y,z;
    	while(scanf("%d%d%d",&x,&y,&z)!=EOF){
    		x--; y--; z--;
    		t=max(max(x,y),z);
    		LL ans=0;
    		for(int i=1;i<=t;i++){
    			ans+=((LL)mobi[i]*(LL)(x/i)*(LL)(y/i)*(LL)(z/i)+(LL)mobi[i]*(LL)(x/i)*(LL)(y/i)+(LL)mobi[i]*(LL)(x/i)*(LL)(z/i)+(LL)mobi[i]*(LL)(y/i)*(LL)(z/i));
    		}
    		ans+=3;
    		printf("%lld
    ",ans);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Date类型 方法
    迭代方法和归并函数
    js快速排序方法
    reset
    水平垂直居中
    css清除浮动
    box-shadow
    display---我的第一篇博客
    centos7基础安装
    aws和ufile挂载数据盘EBS
  • 原文地址:https://www.cnblogs.com/jie-dcai/p/4004747.html
Copyright © 2020-2023  润新知