POJ1150he Last Non-zero Digit(组合)
题意从尾部找第一个非0的数 这样就可以考虑下怎样会形成0 这个都知道 只有因子2和因子5相遇会形成0 那这样可以先把所有的2和5先抽出来,这样就保证了其它的数相乘就不会再出现0了 这样就可以转换成尾数相乘的结果 当然可能2的个数会剩余 这一部分留到最后去算
step1 抽出所有的5和2 n!里因子x的个数 求法: n/x+gn(n/x);
这样结果就为1 3 7 9 之一 这样就需要求一下尾部3,,7,9的出现的次数,并且可以发现它们都是以4为周期的 包括2
step2 尾部3 7 9出现的次数 f[n] + find(n/2) 因为抽走了2 x出现的次数g[n][x] = n/10+(n%10>=x)+ggn(n/5)因为抽走了5
最后再把2的影响补上
题意求N!/(n-m)! 因为N!包含(n-m)! 故可以通过各个数出现的次数相减求得最后的结果
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 100000
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
int o[][];
int p[][];
int gn(int n,int x)
{
if(n==)
return ;
return n/+(n%>=x)+gn(n/,x);
}
int ggn(int n,int x)
{
if(n==)
return ;
return gn(n,x)+ggn(n/,x);
}
int find0(int n,int x)
{
if(n==) return ;
return n/x+find0(n/x,x);
}
int main()
{
int n,m;
p[][] = ,p[][] = ,p[][] = ,p[][] = ;
p[][] = ,p[][] = ,p[][] = ,p[][] = ;
p[][] = ,p[][] = ,p[][] = ,p[][] = ;
p[][] = ,p[][] = ,p[][] = ,p[][] = ;
while(cin>>n>>m)
{
memset(o,,sizeof(o));
m = n-m;
o[][] = find0(n,);
o[][] = find0(m,);
o[][] = find0(n,);
o[][] = find0(m,); o[][] = ggn(n,);
o[][] = ggn(n,);
o[][] = ggn(n,);
o[][] = ggn(m,);
o[][] = ggn(m,);
o[][] = ggn(m,);
o[][] -= o[][];
o[][] -= o[][];
int a = o[][]-o[][];
int b = o[][]-o[][];
int c = o[][]-o[][];
int k = o[][]-o[][];
int ans = ;
if(a) ans*=p[][a%];
if(b) ans*= p[][b%];
if(c) ans*= p[][c%];
if(k) ans*= p[][k%];
cout<<ans%<<endl;
}
return ;
}
POJ1150he Last Non-zero Digit(组合)的更多相关文章
- [Swift]LeetCode902. 最大为 N 的数字组合 | Numbers At Most N Given Digit Set
We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}. (Not ...
- BZOJ 4421: [Cerc2015] Digit Division 排列组合
4421: [Cerc2015] Digit Division 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4421 Descripti ...
- [LeetCode] 902. Numbers At Most N Given Digit Set 最大为 N 的数字组合
We have a sorted set of digits D, a non-empty subset of {'1','2','3','4','5','6','7','8','9'}. (Not ...
- Digit Division(排列组合+思维)(Gym 101480D )
题目链接:Central Europe Regional Contest 2015 Zagreb, November 13-15, 2015 D.Digit Division(排列组合+思维) 题解: ...
- [leetcode] 题型整理之排列组合
一般用dfs来做 最简单的一种: 17. Letter Combinations of a Phone Number Given a digit string, return all possible ...
- Project Euler 90:Cube digit pairs 立方体数字对
Cube digit pairs Each of the six faces on a cube has a different digit (0 to 9) written on it; the s ...
- 【CF521C】【排列组合】Pluses everywhere
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote ...
- USB组合设备 Interface Association Descriptor (IAD)
Communication Device Class,简称CDCUSB Compound Device,USB复合设备USB Composite Device,USB组合设备 摘要USB复合设备 Co ...
- php如何判断字符串是否是字母和数字的组合
转载自百度 /其实判断是否是字母和数字或字母数字的组合还可以用PHP ctype_alnum函数 if(!ctype_alnum($vipurl)){ echo '只能是字母或数字的组合';exit; ...
随机推荐
- (31)java web的hibernate使用-一级缓存,二级缓存
参考:https://blog.csdn.net/miachen520/article/details/52195832 hibernate自带一级缓存 和 二级缓存 一,一级缓存: 基于Sessio ...
- golang基础-WaitGroup、kafka消费者
kafka消费者 以下博客是通过生产者创建.发送消息至kafka 博客链接 现在我们站在消费者的角度,来进行收取消息 package main import ( "fmt" &qu ...
- (linux)自旋锁及其衍生锁
自旋锁 毫秒以下. 自旋锁用于多个CPU系统中,在单处理器系统中,自旋锁不起锁的作用,只是禁止或启用内核抢占.在自旋锁忙等待期间,内核抢占机制还是有效的,等待自旋锁释放的线程可能被更高优先级的线程 ...
- 原:maven+springMVC+mybatis+junit详细搭建过程
阅读目录 1. 工程目录结构整理清楚 2. 引入依赖包 3. 配置数据库连接属性 4. 配置spring配置文件 5. java代码编写(model,dao,service层代码) 6. m ...
- codeforces 691A A. Fashion in Berland(水题)
题目链接: A. Fashion in Berland 题意: 思路: AC代码: //#include <bits/stdc++.h> #include <iostream> ...
- 洛谷P4316绿豆蛙的归宿——期望
题目:https://www.luogu.org/problemnew/show/P4316 期望水题,从终点向起点推,因为是DAG,所以拓扑序推过去即可. 代码如下: #include<ios ...
- vs 发布网站的时候不编译
vs2010 vs2008
- Struts2 关于返回type="chain"的用法.
1.转自:https://blog.csdn.net/wuye/article/details/73274852 功能与redirect的action转发类似,不过与redirectaction转 ...
- JDK7中匿名内部类中使用局部变量要加final,JDK8中不需要,但jdk会默认加上final
今天看书的时候看到了局部内部类,书上说局部内部类可以访问局部变量,但是必须是final的.因为局部变量在方法调用之后就消失了,使用final声明的话该局部变量会存入堆中,和内部类有一样的声明周期.但是 ...
- centos7安装redis3.2.12
1.准备安装包,放在/usr/local/src/ 2.解压安装包,解压到/usr/local/ tar zxf redis-3.2.12.tar.gz -C /usr/local/ 3.cd /us ...