POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数
题意:给一些数,求在这些数中找出四个数互质的方案数。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int maxn=;
const long long modn=;
int n;
int a[maxn*]={};
long long cnt[maxn]={},f[maxn]={};
long long mic[maxn]={},su[maxn]={},tot=;
bool vis[maxn]={};
int main(){
mic[]=;
for(int i=;i<=maxn;i++){
if(!vis[i]){
su[++tot]=i;
mic[i]=-;
}
for(int j=;j<=tot;j++){
int k=i*su[j];
if(k>maxn)break;
vis[k]=;
if(i%su[j])mic[k]=-mic[i];
else break;
}
}
while(~scanf("%d",&n)){
int ma=;memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
ma=max(a[i],ma);
int w=sqrt(double(a[i]));
for(int j=;j<=w;j++){
if(a[i]%j==){cnt[j]+=;cnt[a[i]/j]+=;}
}
if(w*w==a[i])cnt[w]--;
}
long long ans=;
for(int i=;i<=ma;i++){
if(cnt[i]<||mic[i]==)continue;
ans+=mic[i]*cnt[i]*(cnt[i]-)*(cnt[i]-)*(cnt[i]-)/;
}
printf("%I64d\n",ans);
}
}
POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数的更多相关文章
- POJ3094 Sky Code(莫比乌斯反演)
POJ3094 Sky Code(莫比乌斯反演) Sky Code 题意 给你\(n\le 10^5\)个数,这些数\(\le 10^5\),问这些这些数组成的互不相同的无序四元组(a,b,c,d)使 ...
- POJ Sky Code 莫比乌斯反演
N. Sky Code Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO for ...
- hdu.5212.Code(莫比乌斯反演 && 埃氏筛)
Code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- HDU 5212 Code (莫比乌斯反演)
题意:给定上一个数组,求 析: 其中,f(d)表示的是gcd==d的个数,然后用莫比乌斯反演即可求得,len[i]表示能整队 i 的个数,可以线性筛选得到, 代码如下: #pragma comment ...
- JZYZOJ 1375 双亲数 莫比乌斯反演
http://172.20.6.3/Problem_Show.asp?id=1375 网上搜推理图. 有一段没有写莫比乌斯反演都快忘了..数学能力--,定理完全不会推,但是这道题整体来说应该是比较好写 ...
- luogu2714 四元组统计 莫比乌斯反演 组合数
题目大意 给出一段序列,求其中最大公约数为1的四元组的个数. 思路 我们要用到反演.正难则反的思想.对于每一个大于1的数字\(x\),求出最大公约数为\(x\)的四元组的个数\(g(x)\),然后用排 ...
- POJ 3904 Sky Code (容斥原理)
B - Sky Code Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- poj 3904(莫比乌斯反演)
POJ 3904 题意: 从n个数中选择4个数使他们的GCD = 1,求总共有多少种方法 Sample Input 4 2 3 4 5 4 2 4 6 8 7 2 3 4 5 7 6 8 Sample ...
- POJ 3904 (莫比乌斯反演)
Stancu likes space travels but he is a poor software developer and will never be able to buy his own ...
随机推荐
- 【leetcode 简单】第十五题 加一
给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...
- Vue 传递
今天刷了一遍Vue的API,做个小笔记 父子传递数据时,父组件里标记要传的数据,子组件里用props获取,子组件用$emit('func',args)发布事件,父组件用@func接收. 方法一 par ...
- 简单漂亮的php验证码函数
/* *说明:函数功能是生成验证码 * 参数说明:输入 长度,宽度,高度 */ function vcode($_code_length = , $_width = , $_height = ){ $ ...
- PHP动态修改配置文件——php经典实例
文件结构: index.php 主页 config 配置文件 doUpdate.php 修改功能页 index.php <html> <head> <title>修 ...
- KEA128单片机启动代码分析
;/*****************************************************************************; * @file: startup_SK ...
- 对RSA的认识
#没有经过专业老师的指导,所以您在阅读本文时建议参考即可. 学习视屏:https://www.youtube.com/watch?v=TqX0AHHwRYQ https://www.youtub ...
- Linux端口占用
1.netstat netstat -anp | grep 23232 Sample: [root@BICServer 0825]# netstat -anp | grep 23232 tcp 0 0 ...
- git中如何查看一个文件的修改(更新)历史
有些时候有些文件或文件夹被移除了, 或者更换了路径或被改名了, 想跟踪一下这个文件被修改(更新)的历史, 可以用如下命令: git log -p matser -- filename 格式是: git ...
- sed的额外用法(网摘)
#在我开始动手写一个一个的脚本的时候才会看到更多的用法 1. 在某行的前一行或后一行添加内容(前提是要确定行的内容) # 匹配行前加 sed -i '/allow/ideny' httpd.conf ...
- Java文件上传与下载
文件上传与下载可谓上网中的常见现象.apache为我们准备了用于文件上传与下载的两个jar包(commons-fileupload-1.2.1.jar,commons-io-1.4.jar).我们在w ...