ans=所有的三点排列-共行的-共列的-斜着一条线的

斜着的枚举每个点和原点的gcd,反过来也可以,还能左右,上下挪

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
long long ans,line,row,tot,n,m;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int main(){
scanf("%lld%lld",&n,&m);n++,m++;
tot=n*m;
ans=tot*(tot-1)*(tot-2);
ans/=6;
line=n*(n-1)*(n-2)/6;
row=m*(m-1)*(m-2)/6;
ans-=m*line; ans-=n*row;
for(int i=1;i<n;i++){
for(int j=1;j<m;j++)
{
int k=gcd(i,j);
if(k>1)ans-=2*(k-1)*(n-i)*(m-j);
}
}
printf("%lld\n",ans);
}

bzoj 3505 [Cqoi2014]数三角形 组合的更多相关文章

  1. BZOJ 3505: [Cqoi2014]数三角形 [组合计数]

    3505: [Cqoi2014]数三角形 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注意三角形的三点不能共线. 1<=m,n<=1000 $n++ m++$ $ans ...

  2. BZOJ 3505 [Cqoi2014]数三角形

    3505: [Cqoi2014]数三角形 Description 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个.下图为4x4的网格上的一个三角形.注意三角形的三点不能共线. Input ...

  3. BZOJ 3505: [Cqoi2014]数三角形 数学

    3505: [Cqoi2014]数三角形 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...

  4. Bzoj 3505: [Cqoi2014]数三角形 数论

    3505: [Cqoi2014]数三角形 Time Limits: 1000 ms  Memory Limits: 524288 KB  Detailed Limits   Description

  5. bzoj 3505: [Cqoi2014]数三角形 组合数学

    3505: [Cqoi2014]数三角形 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 478  Solved: 293[Submit][Status ...

  6. BZOJ 3505: [Cqoi2014]数三角形( 组合数 )

    先n++, m++ 显然答案就是C(3, n*m) - m*C(3, n) - n*C(3, m) - cnt. 表示在全部点中选出3个的方案减去不合法的, 同一行/列的不合法方案很好求, 对角线的不 ...

  7. bzoj 3505 [Cqoi2014]数三角形(组合计数)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题意] 在n个格子中任选3点构成三角形的方案数. [思路] 任选3点-3点共线 ...

  8. bzoj 3505 [Cqoi2014]数三角形——排列组合

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3505 好题!一定要经常回顾! 那个 一条斜线上的点的个数是其两端点横坐标之差和纵坐标之差的g ...

  9. BZOJ 3505 [Cqoi2014]数三角形(组合数学)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3505 [题目大意] 给定一个nxm的网格,请计算三点都在格点上的三角形共有多少个. 注 ...

随机推荐

  1. ES6中Promise详解

    Promise,简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果.从语法上说,Promise 是一个对象,从它可以获取异步操作的消息. Promise 提供统一的 AP ...

  2. search a 2D matrix(在二维数组中搜索一个元素)

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  3. Storm 常用命令

    1.启动Nimbus bin/storm nimbus & 2.启动Supervisor bin/storm supervisor & 3.启动UI bin/storm ui & ...

  4. 初识java——运算符和表达式以及注释

    java中有不同的运算符,并且在运算中有着优先级的排序计算,其中++和——的优先级最高,最先计算 运算符注意:1,增量和减量运算符++,——. int a=1++; int b=++1; 其中1++表 ...

  5. datetime的精度

    最近有需要将分钟线的数据进行内联拼接,但时间没有必要精确到秒,微秒. df['datetime'] = pd.to_datetime(df['datetime']) df = df.set_index ...

  6. SQL Server 表的管理_关于完整性约束的详解(案例代码)

    SQL Server 表的管理之_关于完整性约束的详解 一.概述: ●约束是SQL Server提供的自动保持数据库完整性的一种方法, 它通过限制字段中数据.记录中数据和表之间的数据来保证数据的完整性 ...

  7. Space Golf~物理题目

    Description You surely have never heard of this new planet surface exploration scheme, as it is bein ...

  8. Django单元测试简明实践

    1.准备数据模式,Django空库测试需要所有相关数据模式必须在Django中定义,说白了,model不能有managed=Fasle,为了解决这个问题,你必须得有一个managed全部为True的S ...

  9. [ SSH框架 ] Struts2框架学习之一

    一.Struts2框架的概述 Struts2是一种基于MVC模式的轻量级Web框架,它自问世以来,就受到了广大Web开发者的关注,并广泛应用于各种企业系统的开发中.目前掌握 Struts2框架几乎成为 ...

  10. Lenghth of Last Word

    description: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', ...