ACM学习历程—广东工业大学2016校赛决赛-网络赛F 我是好人4(数论)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=5
这个题目一看就是一道数论题,应该考虑使用容斥原理,这里对lcm进行容斥。
不过直接上去是T,考虑到序列中同时存在i和ki的话,其实只需要考虑i,所以先对序列中为倍数的对进行处理。
这里的容斥用了hqw的写法。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long using namespace std; const LL maxN = 1e9;
int n;
int t[], a[], len;
LL ans; void input()
{
scanf("%d", &n);
len = n;
for (int i = ; i < len; ++i)
scanf("%d", &t[i]);
for (int i = ; i < len; ++i)
{
if (t[i] == -) continue;
for (int j = ; j < len; ++j)
{
if (i == j) continue;
if (t[j] == -) continue;
if (t[j]%t[i] == ) t[j] = -;
}
}
int top = ;
for (int i = ; i < len; ++i)
if (t[i] != -)
a[top++] = t[i];
len = top;
sort(a, a+len);
} LL gcd(LL x, LL y)
{
LL r;
while (y != )
{
r = y;
y = x%y;
x = r;
}
return x;
} LL lcm(LL x, LL y)
{
return x/gcd(x, y)*y;
} void dfs(int now, LL num, int sz)
{
if (now == len)
{
if (sz)
{
LL last = maxN/num;
if (sz&) ans -= last;
else ans += last;
}
return;
}
if (num%a[now] == ) return;
dfs(now+, num, sz);
LL t = lcm(num, a[now]);
if (t <= maxN) dfs(now+, t, sz+);
} void work()
{
if (len == && a[] == ) printf("0\n");
else
{
ans = maxN;
dfs(, , );
cout << ans << endl;
}
} int main()
{
//freopen("test.in", "r", stdin);
int T;
scanf("%d", &T);
for (int times = ; times <= T; ++times)
{
input();
work();
}
return ;
}
ACM学习历程—广东工业大学2016校赛决赛-网络赛F 我是好人4(数论)的更多相关文章
- ACM学习历程—广东工业大学2016校赛决赛-网络赛E 积木积水(最值问题 || 动态规划)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=4 这个题目自然会考虑到去讨论最长或者最短的板子. 笔上大概模拟一下的话,就 ...
- ACM学习历程—广东工业大学2016校赛决赛-网络赛D 二叉树的中序遍历(数据结构)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=3 这算是一个胡搞类型的题目.当然肯定是有其数据结构支撑的. 唯一的限制就是 ...
- ACM学习历程—广东工业大学2016校赛决赛-网络赛C wintermelon的魔界寻路之旅(最短路 && 递推)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=2 题目由于要找对称的路径,那么狠明显可以把右下角的每一块加到左上角对应的每 ...
- 广东工业大学2016校赛决赛重现——E积木积水(方法据说很多)
Problem E: 积木积水 Description 现有一堆边长为1的已经放置好的积木,小明(对的,你没看错,的确是陪伴我们成长的那个小明)想知道当下雨天来时会有多少积水.小明又是如此地喜欢二次元 ...
- 广东工业大学2016校赛决赛-网络赛 1169 Problem A: Krito的讨伐 优先队列
Problem A: Krito的讨伐 Description Krito终于干掉了99层的boss,来到了第100层.第100层可以表示成一颗树,这棵树有n个节点(编号从0到n-1),树上每一个节点 ...
- 广东工业大学2016校赛决赛-网络赛 1174 Problem F 我是好人4 容斥
Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...
- 广州工业大学2016校赛 F 我是好人4 dfs+容斥
Problem F: 我是好人4 Description 众所周知,我是好人!所以不会出太难的题,题意很简单 给你n个数,问你1000000000(含1e9)以内有多少个正整数不是这n个数任意一个的倍 ...
- ACM学习历程—NPU1086 随机数 2015年陕西省程序设计竞赛网络预赛(正式赛)C题 (计数排序 || set容器)
Description 开学了,ACM队的边老板想在学校中请一些妹子一起做一项问卷调查,调查妹子们对ACM的了解情况,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100), ...
- ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)
hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strange storehouse in PKU. In this ...
随机推荐
- EasyDarwin开源流媒体服务器Golang版本:服务端录像功能发布
EasyDarwin开源流媒体服务器(www.easydarwin.org)现在使用Go版本实现了.最新的代码提交,已经支持了推流(或者拉流)的同时进行本地存储. 本地存储的原理,是在推流的同时启动f ...
- windowsphone8.1学习笔记之Toast通知
熟悉或者了解wp系统的人都知道wp的Toast,Toast(吐司)通知是在屏幕最顶上弹出来的提示框,它专为与锁屏提醒.磁贴通知和应用中UI结合使用而设计,但它不是MessageDialog.说简单点它 ...
- spring配置中的classpath
1 classpath指WEB-INF下面的classes目录 2 配置成classpath*的话,spring会去所有的classpath中去找,包括lib下面的jar包 对于web app而言,c ...
- 小程序发起post请求回调成功没有数据
get请求时为 header:{ "content-type":'application/json' },POST 请求会将data的值放在Request Payload里面,而不 ...
- 【python】-- RabbitMQ RPC模型
RabbitMQ RPC模型 RPC(remote procedure call)模型说通俗一点就是客户端发一个请求给远程服务端,让它去执行,然后服务端端再把执行的结果再返回给客户端. 1.服务端 i ...
- activiti--5 -----------------Activiti 工作流 流程各个步骤所涉及到的表
ACT_RE_*: 'RE'表示repository. 这个前缀的表包含了流程定义和流程静态资源 (图片,规则,等等). ACT_RU_*: 'RU'表示runtime. 这些运行时的表,包含流程实例 ...
- 提供的STC89C52RC单片机GPS在LCD1602液晶只显示welcome to use问题?
1.使用USB-TTL接GPS单独测试GPS定位在所处环境看是否能定位到. 2.检查自己使用的单片机是不是STC89C52RC型号,提供例程使用的这个型号单片机.如果使用其他51单片机,请先使用STC ...
- Hive2.0的新特性介绍
- 【leetcode刷题笔记】Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- 【leetcode刷题笔记】Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...