HDU 1796 How many integers can you find(容斥)
来源:互联网 发布:mac打字不显示候选框 编辑:程序博客网 时间:2024/05/19 10:33
题意:
输入n,m以及m个数,输出在1~n中能被m个数的其中一个整除的数的数量
解题思路:
用一个数组记录这m个数,以及其中的2个,3个。。。m个数的最小公倍数
能被奇数个数的最小公倍数整除的用+,偶数个用减
#include <iostream>using namespace std;#define ll __int64ll a[2000],b[15];int gcd(int a,int b){if(b==0) return a;else gcd(b,a%b);}int main(){ll n,m;while(cin>>n>>m){ll k=1;a[0]=-1;for(ll i=0;i<m;i++) cin>>b[i];for(ll i=0;i<m;i++){ll l=k;if(b[i]==0) continue;for(ll j=0;j<l;j++){int pi;if(a[j]<0) pi=-a[j];else pi=a[j];int t = gcd(pi,b[i]);a[k++] = -1*a[j]/t*b[i]; }}ll ans=0;for(ll i=1;i<k;i++) {ans = ans+(n-1)/a[i];//cout<<a[i]<<" ";}cout<<ans<<endl;}return 0;}
0 0
- hdu-1796-How many integers can you find(容斥)
- HDU 1796 How many integers can you find 【容斥】
- HDU 1796 How many integers can you find(容斥原理)
- hdu 1796 How many integers can you find(容斥定理)
- hdu 1796 How many integers can you find(容斥原理)
- HDU 1796 How many integers can you find (简单容斥)
- hdu 1796 How many integers can you find(容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- HDU 1796 How many integers can you find(组合数学-容斥原理)
- 容斥定理(1)HDU 1796--How many integers can you find
- hdu 1796 How many integers can you find(容斥原理)
- HDU 1796 - How many integers can you find(容斥原理)
- HDU 1796 How many integers can you find(简单容斥原理)
- HDU 1796 How many integers can you find (容斥原理)
- [ACM] HDU 1796 How many integers can you find (容斥原理)
- HDU 1796 How many integers can you find (数论之容斥)
- hdu-1796 How many integers can you find(容斥原理)
- HDU 1796 How many integers can you find(容斥)
- POJ-3032 Card Trick
- Android ViewPager内容部分随手势上下滑动隐藏与显示Indicator效果的实现
- Oracle Study之--NLS_DATE_FORMAT
- CPU动态调频二:interactive governor
- MySQL单列索引和联合索引
- HDU 1796 How many integers can you find(容斥)
- aidl ( 一 ) activity获取后台service数据
- C高级知识总结
- [_UIAlertShimPresentingViewController shouldAutorotate] is returning YES解决方法
- 第九周 项目3-分数类中的运算符重载(2)
- CCLabelTTF设置第三方字体遇到的问题
- 【J2EE学习】(二)Servlet向JSP传值
- Android Fragment学习笔记(2) ----使用ListFragment显示列表(上)
- java泛型约束和限定