poj 3904 Sky Code(莫比乌斯函数)
来源:互联网 发布:照片转素描软件 编辑:程序博客网 时间:2024/05/14 15:04
莫比乌斯函数,把所有的是i的倍数的数;num[i]如果大于四个就用C(4,num[i])*mu[i]就是答案
#include <iostream>#include <stdio.h>#include <string.h>#define ll long longusing namespace std;const int MAX=11000;int mu[MAX],n,max1;int cnt[MAX];int num[MAX];void init(){ memset(mu,0,sizeof(mu)); mu[1]=1; for(int i=1;i<MAX-10;i++) for(int j=i+i;j<MAX-10;j+=i) mu[j]-=mu[i];}long long solve(){ for(int i = 1; i <= max1; i++) for(int j = i; j <= max1; j += i) num[i] += cnt[j]; ll ans = 0; for(int i = 1; i <= max1; i++) { int x = num[i]; if(x >= 4) ans += (ll) mu[i] * x * (x - 1) * (x - 2) * (x - 3) / 24; } return ans;}int main(){ init(); while(~scanf("%d",&n)) { max1=0; memset(cnt,0,sizeof(cnt)); memset(num, 0, sizeof(num)); for(int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); cnt[tmp] ++; max1 = max(max1, tmp); } if(n<4)printf("0\n"); else printf("%lld\n",solve()); } return 0;}
阅读全文
0 0
- poj 3904 Sky Code(莫比乌斯函数)
- poj 3904 Sky Code 莫比乌斯反演 或 容斥原理
- POJ 3904 Sky Code (容斥+莫比乌斯反演)
- POJ 3904 Sky Code 莫比乌斯反演 容斥原理
- POJ 3904 Sky Code
- POJ 3904 Sky Code
- POJ 3904 Sky Code(容斥)
- POJ 3904 Sky Code(容斥)
- 解题报告:POJ_3904 Sky Code 莫比乌斯反演|容斥
- POJ 3904 Sky Code 解题报告(容斥原理)
- POJ 3904 Sky Code (容斥原理)
- POJ 3904 Sky Code(素因子分解+容斥)
- POJ 3904 Sky Code(813训练题目)题解
- POJ 3904 Sky Code 容斥原理
- poj 3904 sky code 容斥原理
- POJ 3904 Sky Code 容斥原理
- poj 3904 Sky Code【容斥原理】
- 容斥原理:poj 3904 Sky Code
- while语句
- 数据库概论学习笔记------什么是存储引擎
- linux下zookeeper安装
- Mysql查询昨天、今天、明天、7天、本月、上月.....
- Android 开发环境下载地址 -- 百度网盘 adt-bundle android-studio sdk adt 下载
- poj 3904 Sky Code(莫比乌斯函数)
- POJ 2431 Expedition
- 基于Springboot-Netty-Protostuff-ZooKeeper分布式RPC框架
- HDU 6059 Kanade's trio 字典树
- Windows配置node环境以及express模块
- java7 [try-with-resources]
- mycat
- LeetCode 35 Search Insert Position
- 串结构练习——字符串连接