博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1796 (容斥原理)
阅读量:4694 次
发布时间:2019-06-09

本文共 1040 字,大约阅读时间需要 3 分钟。

容斥原理练习题,忘记处理gcd 和 lcm,wa了几发0.0.

#include
#include
#include
using namespace std;typedef long long ll;ll Num[30];ll gcd(ll a,ll b){ return b == 0 ? a : gcd(b,a%b);}int main(){ ll N, M; while(scanf("%lld%lld",&N,&M)!=EOF) { N--; ll num = 0; ll tmp,Cnt = 0; for(int i = 0; i < M; ++i) { scanf("%lld",&tmp); if(tmp == 0) continue; else { Num[Cnt++] = tmp; } } for(int i = 1; i < (1 << Cnt) ; ++i) { ll cnt = 0, tmp = 1; for(int j = 0; j < Cnt; ++j) { if(i & (1 << j)) { cnt++; tmp =tmp /gcd(tmp,Num[j]) * Num[j]; } //printf("%lld\n",tmp); } if(cnt & 1) num += (N/tmp); else num -= (N/tmp); } printf("%lld\n",num); } return 0;}

转载于:https://www.cnblogs.com/aoxuets/p/4731321.html

你可能感兴趣的文章
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
windows下mysql密码忘了怎么办?【转】
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>
RAMPS1.4 3d打印控制板接线与测试1
查看>>
python with语句中的变量有作用域吗?
查看>>
24@Servlet_day03
查看>>
初级ant的学习
查看>>
redis数据结构--String
查看>>
POJ 3279 Fliptile (二进制枚举)
查看>>
memcached 细究(三)
查看>>
使用svn——项目的目录布局
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>