51nod 1284 2 3 5 7的倍数(容斥原理)
来源:互联网 发布:mysql自定义函数 编辑:程序博客网 时间:2024/06/11 02:03
先求出2,3,5,7的倍数的个数,然后用n减掉就好了。。
#include <iostream>#include <algorithm>using namespace std;typedef long long ll;ll gcd(ll a, ll b){ ll temp; while(b) { temp = a % b; a = b; b = temp; } return a;}ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}int main(){ ll n; cin >> n; ll sum = n/2+n/3+n/5+n/7; sum = sum - n/lcm(2,3)-n/lcm(2,5)-n/lcm(2,7)-n/lcm(3,5)-n/lcm(3,7)-n/lcm(5,7); sum = sum + n/lcm(lcm(2,3),5) + n/lcm(lcm(2,3),7) + n/lcm(lcm(3,5),7) + n/lcm(lcm(2,5),7); sum = sum - n/lcm(lcm(2,3),lcm(5,7)); cout << n-sum <<endl; return 0;}
0 0
- 51nod 1284 2 3 5 7的倍数(容斥原理)
- 【51Nod】1284 - 2 3 5 7的倍数(容斥原理 & 二进制优化)
- 51Nod 1284 2 3 5 7的倍数 (容斥原理)
- 51nod 1284 2、3、5、7的倍数 (容斥原理)
- 51nod 1284 2 3 5 7的倍数(容斥原理)
- 51nod-1284 2 3 5 7的倍数 (容斥原理)
- 51nod 1284:2 3 5 7的倍数 容斥原理
- 51nod 1284 2 3 5 7的倍数 容斥原理
- 51nod 1284 2 3 5 7的倍数(基础容斥原理)
- 51 Nod 1284 2 3 5 7的倍数(容斥原理)
- 51nod 1284 2 3 5 7的倍数 容斥原理
- 51nod 1284 2 3 5 7的倍数 容斥原理
- 51nod 1284 2 3 5 8的倍数(容斥原理)
- 51nod 1284 2 3 5 7的倍数(容斥定理)
- 51nod 1284 2 3 5 7的倍数(容斥)
- 51nod 1284 2 3 5 7的倍数(容斥)
- 51nod 1284 2 3 5 7的倍数(容斥定理)
- 51nod - 1284 2 3 5 7的倍数(容斥)
- HDU6029(思维题)
- RARP应用场景
- 练习题 No.16 二叉搜索树
- 分布式的概念
- 关于QAxObject开发excel时出现的问题解决
- 51nod 1284 2 3 5 7的倍数(容斥原理)
- idea 导入eclipse maven项目
- 《操作系统》第8章:虚拟内存
- 浅析Beautiful Soup库和Lxml库
- Error running app:Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled问题解决
- crontab误删操作的恢复与防范
- 欢迎使用CSDN-markdown编辑器
- cf Educational Codeforces Round 20 E. Roma and Poker
- 查看CPU信息