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; ...
随机推荐
- Mac JDK 多版本共存
1. 安装各JDK版本,安装后通过Java -version检测是否安装好 2. 打开~/.bash_profile,没有的话创建 vim ~/.bash_profile ...
- iconfont的图文混排
最近在使用iconfont排版,但是发现完全没法混到textarea中. 希望借助 contentEditable 解决这个问题
- NIO与IO的区别
nio是new io的简称,从jdk1.4就被引入了.现在的jdk已经到了1.6了,可以说不是什么新东西了.但其中的一些思想值得我来研究.这两天,我研究了下其中的套接字部分,有一些心得,在此分享. ...
- [Selenium] 操作浏览器 Cookies
WebDriver 提供了一系列 Cookies 的操作来获取.填写.删除 Cookies 的方法,节省了多次在登陆页面的查找元素并填写登录信息的时间. 1)获取 Cookies ,并保存到文件中以备 ...
- 【前端】CentOS 7 系列教程之四: 配置 git 服务器自动部署
转载请注明出处:http://www.cnblogs.com/shamoyuu/p/linux_4.html 安装pm2守护进程,备用 npm install -g pm2 创建/srv/www文件夹 ...
- Servlet3.0之九:web模块化
一.使用web-fragment.xml 在Servlet 3.0中,可以使用标注来设置Servlet的相关信息.实际上,Web容器并不仅读取/WEB-INF/classes中的Servlet标注信息 ...
- caffe 入门实例3 fine-turning
占坑,使用fine-turning初始化参数...
- View Controller Programming Guide for iOS---(六)---Responding to Display-Related Notifications
Responding to Display-Related Notifications 响应跟显示相关的通知 When the visibility of a view controller’s vi ...
- python学习笔记2-条件语句
#条件语句 ''' if 判断条件: 执行语句…… else: 执行语句…… ''' flag = False name = 'python' if name == 'python': # 判断变量否 ...
- hibernate的基础学习--一对一关联
一对一关系以丈夫和妻子模型 配置文件 妻子配置文件: <?xml version="1.0" encoding="utf-8" ?> <!DO ...