• 优美等式


    想不到吧,我被卡常了。

    http://iai.sh.cn/problem/612

    #pragma GCC optimize("Ofast","-funroll-loops")
    #pragma GCC target("sse4.1","sse4.2","ssse3","sse3","sse2","sse","avx2","avx","popcnt","tune=native")
    #include <bits/stdc++.h>
    #define pb push_back
    using namespace std;
    #define N (int)(2e6+5)
    #define M (int)(2e6)
    #define ull unsigned long long
    #define base 19260817
    #define ll long long
    bool vis[N];
    ull val[N],B[N];
    int pri[N],nw[N],cnt,las[N];
    int n,m; 
    ll ans;
    unordered_map<ull,int>mp;
    
    void init() {
    	for(int i=1;i<=M;i++) nw[i]=i,las[i]=0;
    	for(int i=2;i<=M;i++) {
    		if(!vis[i]) {
    			pri[++cnt]=i; val[i]=1; las[i]=cnt; nw[i]=1;
    			for(int j=i+i;j<=M;j+=i) {
    				vis[j]=1;
    				int qwq=0;
    				while(nw[j]%i==0) ++qwq,nw[j]/=i;
    				val[j]=val[j]*B[cnt-las[j]];
    				if(qwq&1) ++val[j];
    				las[j]=cnt;
    			}
    		}
    	}
    	for(int i=1;i<=M;i++) val[i]=val[i]*B[cnt-las[i]];
    }
    
    signed main() {
    //	freopen("xgf.out","w",stdout);
    	cin.tie(0); ios::sync_with_stdio(false);
    	B[0]=1; for(int i=1;i<=M;i++) B[i]=B[i-1]*base;
    	init();
    //	for(int i=1;i<=M;i++) {
    //		int x=i,las=0; ull h=0;
    ////		cout<<x<<'\n';
    //		for(int j:vec[i]) {
    //			int qwq=0;
    //			while(x%j==0) ++qwq,x/=j;
    ////			cout<<id[j]<<" "<<las<<'\n';
    //			h=h*B[id[j]-las]; las=id[j];
    //			if(qwq&1) ++h;
    //		}
    
    //		h=h*B[cnt-las];
    //		val[i]=h;
    //	}
    	cin>>n>>m;
    	if(n<m) swap(n,m);
    	for(int i=1;i<=m;i++) ++mp[val[i]];
    	for(int i=1;i<=n;i++) ans+=mp[val[i]];
    	cout<<ans; 
    	return 0;
    }
    
  • 相关阅读:
    unittest框架assert断言
    python logging 总结
    好文章推荐 数据库mysql
    python 日志模块 日志格式
    django admin 后台总结(转载)
    xpath解析html标签
    lua 排序table.sort()用法
    lua 随机数 math.random()和math.randomseed()用法
    三种方法获取 lua时间戳
    crontab调用python脚本新思路
  • 原文地址:https://www.cnblogs.com/xugangfan/p/16016973.html
Copyright © 2020-2023  润新知