HDU5514 Frogs
/*
HDU5514 Frogs
http://acm.hdu.edu.cn/showproblem.php?pid=5514
容斥原理
*
*
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
//#define test
using namespace std;
const long long Nmax=1e5;
long long n,m,a[Nmax];
long long book[Nmax];
long long p[Nmax];
int cnt;
long long num[Nmax];
long long gcd(long long a,long long b)
{
if(b==0LL)
return a;
return gcd(b,a%b);
} int main()
{
long long t;
#ifdef test
while()
{
long long a,b;
scanf("%lld%lld",&a,&b);
printf("%lld\n",gcd(a,b));
}
#endif
scanf("%lld",&t);
for(long long ttt=;ttt<=t;ttt++)
{
scanf("%lld%lld",&n,&m);
int flag=;
for(long long i=;i<=n;i++)
{
scanf("%lld",&a[i]);
a[i]=gcd(a[i],m);
if(a[i]==)
flag=;
}
if(flag)
{
long long ans=(m-1LL)*m/2LL;
printf("Case #%lld: ",ttt);
printf("%lld\n",ans);
continue;
}
long long ans=0LL;
cnt=;
for(int i=;i*i<=m;i++)
{
if(m%i)
continue;
p[++cnt]=i;
if(i*i!=m)
p[++cnt]=m/i;
}
sort(p+,p++cnt);
for(int i=;i<=cnt;i++)
book[i]=num[i]=;
for(int i=;i<=n;i++)
{
for(int j=;j<=cnt;j++)
if(p[j]%a[i]==)
book[j]=;
}
for(int i=;i<=cnt;i++)
{
if(book[i]!=num[i])
{
long long tmp=m/p[i];
ans+=tmp*(tmp-1LL)/2LL*p[i]*(book[i]-num[i]);
tmp=book[i]-num[i];
for(int j=i+;j<=cnt;j++)
if(p[j]%p[i]==)
num[j]+=tmp;
}
} printf("Case #%lld: ",ttt);
printf("%lld\n",ans);
}
return ;
}
HDU5514 Frogs的更多相关文章
- 从HDU2588:GCD 到 HDU5514:Frogs (欧拉公式)
The greatest common divisor GCD(a,b) of two positive integers a and b,sometimes written (a,b),is the ...
- 【做题】hdu5514 Frogs——另类容斥
题意是给出n个m的约数,问[0,m-1]中至少被其中一个约数整除的整数和.(n<=10000,m<=1000000000) 直接容斥的话,是2^n再拖个log的复杂度,加上当前的数大于m时 ...
- POJ 1659 Frogs' Neighborhood(Havel-Hakimi定理)
题目链接: 传送门 Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Description 未名湖附近共有N个大小湖泊L ...
- CF# Educational Codeforces Round 3 F. Frogs and mosquitoes
F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input stan ...
- Frogs' Neighborhood
Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 7920 Accepted: 33 ...
- HDU 5514 Frogs 容斥定理
Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...
- poj 1659 Frogs' Neighborhood (DFS)
http://poj.org/problem?id=1659 Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total S ...
- poj 1659 Frogs' Neighborhood (贪心 + 判断度数序列是否可图)
Frogs' Neighborhood Time Limit: 5000MS Memory Limit: 10000K Total Submissions: 6076 Accepted: 26 ...
- codeforces 609F. Frogs and mosquitoes 二分+线段树
题目链接 F. Frogs and mosquitoes time limit per test 2 seconds memory limit per test 512 megabytes input ...
随机推荐
- C#之简易猜数字游戏
游戏规则说明: 由系统生成一个随机数,玩家有三次猜数字的机会,如果在三次内猜出数字反馈玩家猜对了,否则Game Over! 代码设计说明: 1.首先设计一个简易的欢迎界面,并提示玩家是否开始游戏: p ...
- wpf Textbox 点击选中全部文本
用法:依赖属性 SelectTextOnFocus.Active = True public class SelectTextOnFocus : DependencyObject { public s ...
- c25---条件编译
// // main.c // 条件编译(宏定义是简单的替换,要给参数和结果都加括号) #include <stdio.h> #define SCORE 90 #define DEBUG ...
- 国外物联网平台初探(五) ——Exosite Murano
定位 Murano是一个基于云的IoT软件平台,提供安全.可扩展的基础设施,支持端到端的生态系统,帮助客户安全.可扩展地开发.部署和管理应用.服务以及联网产品. 功能 Murano平台简化了整个IoT ...
- Intel 的 MKL是可以用来训练的——官方的实验也提到了训练
TensorFlow如何充分使用所有CPU核数,提高TensorFlow的CPU使用率,以及Intel的MKL加速 转载 2017年09月07日 16:34:58 标签: cpu / gpu 转载 ...
- k8s Gitlab CI/CD 之自动编译Docker镜像并推送到指定的Registry
环境介绍: 说明 节点 ip 系统 Gitlab Server git.ds.com 10.0.1.179 CentOS 7.5.1804 Gitlab Runner 10.0.1.178 Cen ...
- codeforces 708ALetter Cyclic Shift
2019-05-18 09:51:19 加油,加油,fightting !!! https://www.cnblogs.com/ECJTUACM-873284962/p/6375011.html 全为 ...
- c语言open()介绍
2013-09-0914:40:13 1. 头文件: #include <sys/types.h> #include <sys/stat.h> #include <fcn ...
- 8、List接口的特点及其相关功能
/* * Collection * |--List * 元素有序(指的是存储顺序和取出顺序是否一致),可重复. * |--Set * 元素无序,唯一. */ /* * List的特有功能: * A:添 ...
- Android ToolBar标题文字居中的方法
在项目的开发中,使用苹果手机的产品,出的界面效果图极有可能(我这里是一定)完全是按照苹果的界面风格来出的,例如界面顶部的title文字位置是水平居中 如图: 那么问题来了,当我们使用ToolBar控件 ...