//作者:pb2 博客:https://www.luogu.com.cn/blog/pb2/ 或 http://www.cnblogs.com/p2blog
//博客新闻1:"WPS开机自启,每10秒 会访问一次百度 的IP(36.152.44.95/)!"
//新闻二:"三种安全程度的百度!(其中两种"不安全")"
#include <iostream>
using namespace std;
int main() {
int n, m;//n=people num;m=give ball num
cin >> n >> m;
if (m == 1) {//special m
cout << 0;
return 0;
}
else if (m == 2) {
cout << n - 1;
return 0;
}
else if (m == 3) {
cout << (n - 1) * (n - 2);
return 0;
}//special ways
n--;//a person can not give ball to himself(so -1)
int en = n - 1, now = 1;//except o=one=1(xiao man)(so -1 again)
long long o = 1, e = 0;//o=one=1(xiao man) e=else=2,3,4... now=m (now)
long long obefore = o;//like temp in the function "swap()"
while (now != m - 2) {
o = e;
e = en * e + n * obefore;
obefore = o;
now++;
}
cout << o * n + e * en;
return 0;
}

最新文章

  1. windows10的第一天使用总结
  2. [java] 汇率换算器实现(1)
  3. Adding New Functions to MySQL(User-Defined Function Interface UDF、Native Function)
  4. crossplatform---Nodejs in Visual Studio Code 08.IIS
  5. 简单使用Dos命令关闭计算机
  6. python:时间处理模块
  7. 在公网上布署Web Api的时候,不能调用,返回404
  8. 禁用谷歌字体解决WordPress访问速度过慢问题
  9. spoj TSUM - Triple Sums fft+容斥
  10. Directx11学习笔记【十四】 使用最新的Effect框架和SDK
  11. 【Machine Learning in Action --5】逻辑回归(LogisticRegression)从疝气病预测病马的死亡率
  12. 05_NoSQL数据库之Redis数据库:Redis的常用命令,键值相关命令和服务器相关命令
  13. 阿里云服务器公网Ip外网无法访问
  14. Burnside引理的感性证明
  15. Python之列表推导式
  16. ActiveMQ producer 流量控制
  17. 节点的启动与关闭 ros::init()解析(c++)
  18. (C/C++学习笔记) 十. 函数
  19. Laravel 5.4: 特殊字段太长报错
  20. Oracle存储过程中调用DBLink同义词出现错误:PLS-00201: 必须声明标识符

热门文章

  1. Pandas切片操作:很容易忽视的SettingWithCopyWarning
  2. 消息队列,RabbitMQ、Kafka、RocketMQ
  3. 软件——IDEA 超实用使用技巧分享
  4. Flutter 1.17版本重磅发布
  5. ocaml 和coq 安装
  6. 设计模式之GOF23策略
  7. {bzoj2338 [HNOI2011]数矩形 &amp;&amp; NBUT 1453 LeBlanc}平面内找最大矩形
  8. Python 简明教程 --- 3,Python 基础概念
  9. RESTful设计中的常见疑问
  10. 2018-07-01 jq效果