bzoj 2190: [SDOI2008]仪仗队 【容斥】
2016-03-15 19:35
393 查看
题目链接:bzoj 2190: [SDOI2008]仪仗队
去掉第一行和第一列,然后容斥。之后加2就好了。
AC代码:
去掉第一行和第一列,然后容斥。之后加2就好了。
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #include <stack> #define PI acos(-1.0) #define CLR(a, b) memset(a, (b), sizeof(a)) #define fi first #define se second #define ll o<<1 #define rr o<<1|1 using namespace std; typedef long long LL; typedef pair<int, int> pii; const int MAXN = 1e6+1; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; void getmax(int &a, int b) {a = max(a, b); } void getmin(int &a, int b) {a = min(a, b); } void add(LL &x, LL y) { x += y; x %= MOD; } int p[1001], k; void getp(int n) { k = 0; for(int i = 2; i * i <= n; i++) { if(n % i == 0) { p[k++] = i; while(n % i == 0) n /= i; } } if(n > 1) p[k++] = n; } LL q[MAXN]; LL nop(LL m) { int top = 0, t; q[top++] = -1; for(int i = 0; i < k; i++) { t = top; for(int j = 0; j < t; j++) { q[top++] = q[j] * p[i] * (-1); } } LL sum = 0; for(int i = 1; i < top; i++) sum += m / q[i]; return sum; } int main() { int n; scanf("%d", &n); n--; int ans = n; for(int i = 2; i <= n; i++) { getp(i); ans += n - nop(n); } cout << ans + 2 << endl; return 0; }
相关文章推荐
- 快速排序(分治法O(nlogn))
- 通用JSON生成器3
- Makefile 学习日记(三)——makefile的瘦身
- 从MAC上生成pem文件用于推送
- springmvc /struts2工作机制
- 第3周项目1 个人所得税计算器
- iOS小技巧17-iPhone如何安装ipa包
- 一个大神程序员的使命感究竟应该是什么
- 搞清arguments,callee,caller
- lightoj 1234 - Harmonic Number 【分块打表】
- hdoj 5642 King's Order 【数位dp】
- iOS UI 的坑:不要 remove UITableViewCell 的 contentView
- 关于final
- 最大子序列-NlogN
- 关于“只有注册用户登录后才能阅读该文”
- 20160310第一题
- 图像识别数据库
- hdoj 5641 King's Phone 【模拟】
- LinuxMySQL主从配置
- 网易2016年研发工程师编程题(1)