3518: 点组计数
来源:互联网 发布:淘宝网阿里旺旺打不开 编辑:程序博客网 时间:2024/06/14 02:54
3518: 点组计数
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 113 Solved: 62
[Submit][Status][Discuss]
Description
平面上摆放着一个n*m的点阵(下图所示是一个3*4的点阵)。Curimit想知道有多少三点组(a,b,c)满足以a,b,c三点共线。这里a,b,c是不同的3个点,其顺序无关紧要。(即(a,b,c)和
(b,c,a)被认为是相同的)。由于答案很大,故你只需要输出答案对1,000,000,007的余数就可以了。
Input
有且仅有一行,两个用空格隔开的整数n和m。
Output
有且仅有一行,一个整数,表示三点组的数目对1,000,000,007的余
数。(1,000。000。007是质数)
Sample Input
3 4
Sample Output
2 0
HINT
对于100%的数据,1< =N.m< =50000
Source
#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>#include<vector>#include<queue>#include<set>#include<map>#include<stack>#include<bitset>#define min(a,b) ((a) < (b) ? (a) : (b))#include<ext/pb_ds/priority_queue.hpp>using namespace std; const int maxn = 5E4 + 50;typedef long long LL;const LL mo = 1000000007; int n,m,Ans,tot,mu[maxn],pri[maxn],sum[maxn];bool not_pri[maxn]; inline int Mul(const LL &x,const LL &y) {return x * y % mo;}inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}inline int Dec(const int &x,const int &y) {return x - y >= 0 ? x - y : x - y + mo;} int C(int N){ int A = N,B = N - 1,C = N - 2; if (A % 2 == 0) A /= 2; else if (B % 2 == 0) B /= 2; else if (C % 2 == 0) C /= 2; if (A % 3 == 0) A /= 3; else if (B % 3 == 0) B /= 3; else if (C % 3 == 0) C /= 3; return Mul(A,Mul(B,C));} inline int Sum(int tmp,int N,int M){ int A = Mul(N,M); int B = Mul(sum[N],tmp); return Dec(A,B);} inline int Solve(int d,int N,int M){ int ret = 0; for (int t = 1; t <= N; t++) { if (!mu[t]) continue; int A = Sum(Mul(d,t),N / t,n); int B = Sum(Mul(d,t),M / t,m); ret = Add(ret,Mul(mu[t],Mul(A,B))); } return ret;} int Calc(){ int ret = 0; for (int d = 2; d <= n; d++) ret = Add(ret,Mul(d - 1,Solve(d,n / d,m / d))); return ret;} int main(){ #ifdef DMC freopen("DMC.txt","r",stdin); #endif cin >> n >> m; if (n > m) swap(n,m); mu[1] = 1; for (int i = 2; i < maxn; i++) { if (!not_pri[i]) pri[++tot] = i,mu[i] = mo - 1; for (int j = 1; j <= tot; j++) { int Nex = i * pri[j]; if (Nex >= maxn) break; not_pri[Nex] = 1; if (i % pri[j] == 0) break; mu[Nex] = Mul(mu[i],mo - 1); } } for (int i = 1; i < maxn; i++) sum[i] = Add(i,sum[i - 1]); Ans = Add(Mul(C(n),m),Mul(C(m),n)); Ans = Add(Ans,Mul(2,Calc())); cout << Ans << endl; return 0;}
0 0
- 3518: 点组计数
- 折点计数
- CCF 折点计数
- CCF 折点计数
- 折点计数
- 折点计数
- java折点计数
- ccf 折点计数
- ccf201604-1拆点计数
- 201604-1 折点计数
- java-csp-折点计数
- ccf试题 折点计数
- CCF201604-1-折点计数
- CCFCSP201604-1折点计数
- (JAVA)折点计数
- ccf认证折点计数
- 201604-1折点计数
- CCF之折点计数
- android 再按一次后退键退出应用程序
- 双指拖动缩放图片
- 使用FileObserver对sdcard文件或文件夹监控
- 在ViewFlipper中使用Rotate3dAnimation旋转切换界面效果
- 初识QT2
- 3518: 点组计数
- Android 数据库打包随APK发布
- 高并发高可用的 架构实践
- 使用Service和BroadcastReceiver实时监听网络状态
- Android-20170410
- ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)
- BZOJ 4521 [Cqoi2016] 手机号码
- 领域驱动设计之领域模型
- 利用录音AudioRecord实现吹一吹效果