您的位置:首页 > 其它

bzoj3505

2015-09-04 20:21 417 查看
枚举对角线。。。

#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
#define clr(a,x) memset(a,x,sizeof(a))
#define rep(i,l,r) for(int i=l;i<(r);i++)
typedef long long ll;
using namespace std;
int read()
{
char c=getchar();
int ans=0,f=1;
while(!isdigit(c)){
if(c=='-') f=-1;
c=getchar();
}
while(isdigit(c)){
ans=ans*10+c-'0';
c=getchar();
}
return ans*f;
}
int n,m;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
ll f(ll x){
return x*(x-1)*(x-2)/6;
}
int main()
{
n=read();m=read();++n;++m;
ll ans=f(n*m)-ll(n)*f(m)-ll(m)*f(n);
rep(i,1,n){
rep(j,1,m){
ans-=(gcd(i,j)-1)*(n-i)*(m-j)<<1;
}
}
cout<<ans<<endl;
return 0;
}


View Code

3505: [Cqoi2014]数三角形

Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 771 Solved: 471
[Submit][Status][Discuss]

Description

给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个。下图为4x4的网格上的一个三角形。

注意三角形的三点不能共线。

Input

输入一行,包含两个空格分隔的正整数m和n。

Output

输出一个正整数,为所求三角形数量。

Sample Input

2 2

Sample Output

76

数据范围
1<=m,n<=1000

HINT

Source

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: