http://acm.uestc.edu.cn/#/problem/show/1544

考虑一下2、2、2这样的情况。答案应该是n / 2

如果只选一个的情况下,对答案的贡献是正的,但是这里有三个,也就是我们统计了3 * n / 2,统计多了。

那么对于任选两个数的情况,有三种,(2, 2) * 3,分别都是不同位置的2,

/**************************************/

我做的时候是发现,先讨论只有

2、2的情况,也就是只有两个数的时候,ans = 0,这个时候,先模拟上面的,只选一个,答案是2 * n / 2

那么枚举两个数的情况,应该就是要ans -= 2 * n / (lcm(2, 2))

要减2倍,不然答案不是0.

/**************************************/

那么上面也是,有三种(2, 2)的情况,ans -= 3 * 2 * n / (lcm(2, 2))

那么现在是-3 * n / (lcm(2, 2))

然后还有一种的就是枚举三个的情况,要使答案是n / 2,那么应该加上4 * n / (lcm(2, 2))

然后得到的规律是1 << (sel - 1),sel是选的数字个数。

完全是瞎比比的,数学不好。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
int n, has;
const int maxn = + ;
int arr[maxn];
LL ans;
LL LCM(LL a, LL b) {
return a / __gcd(a, b) * b;
}
void dfs(int cur, int sel, LL theLcm) {
if (theLcm > n) return;
if (cur == has + ) {
if (!sel) return;
if (sel & ) {
ans += ( << (sel - )) * (n / theLcm);
} else {
ans -= ( << (sel - )) * (n / theLcm);
}
return;
}
dfs(cur + , sel, theLcm);
dfs(cur + , sel + , LCM(theLcm, arr[cur]));
}
void work() {
ans = ;
scanf("%d%d", &n, &has);
for (int i = ; i <= has; ++i) {
scanf("%d", &arr[i]);
}
dfs(, , );
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

还有就是数据中没有15个大质数这样的情况,数据比较弱。

最新文章

  1. 异步控制---实现函数asyncAll,在执行完传入数组中func1,func2,func3异步函数后,输出“end”
  2. Java设计模式10:观察者模式
  3. 2015暑假多校联合---Expression(区间DP)
  4. 【项目】&#39;NSRangeException&#39;, reason: &#39;*** -[__NSArrayM removeObjectAtIndex:]: index 2 beyond bounds [0 .. 1]&#39;
  5. 瓦片地图与geoserver发布
  6. Latex 页面样式
  7. 黑马程序员——JAVA基础之IO流缓冲区,转换流,字节流
  8. str转unsigned int
  9. 统计学习方法 AdaBoost
  10. AS3 Graphics 多次绘制
  11. lua的学习
  12. C语言程序设计第二次作业0
  13. python&amp;django 实现页面中关联查询小功能(中级篇)
  14. Git(2):本地版本库的一些操作
  15. elemet-ui图标—特殊字符的unicode编码表
  16. Scala(三)
  17. ubuntu18.04.2LTS下如何用五笔输入法 --Linux
  18. 利用this属性实现点击按钮变色.选中效果
  19. java程序存入数据库中文乱码解决方案
  20. C#对象内部属性排序测试

热门文章

  1. mysql初始化命令及其他命令
  2. BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】
  3. [HAOI 2012] Road
  4. calico在docker上的部署及验证
  5. bzoj4259
  6. ubuntu12.04下有线网无电缆插入问题
  7. 【转】cache buffer chain 第一篇
  8. Flutter实战视频-移动电商-56.购物车_商品数量控制区域制作
  9. python 网络编程(网络基础之网络协议篇)
  10. 洛谷 - P1390 - 公约数的和 - 莫比乌斯反演 - 欧拉函数