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; ...
随机推荐
- Java WebSocket库:https://github.com/TooTallNate/Java-WebSocket
https://github.com/TooTallNate/Java-WebSocket 以下是简单示例: import com.google.gson.JsonObject; import com ...
- update外联表,用另一个表数据更新本表数据
update s set s.classbid = lc.itemidfrom dbo.Lv_servers as s INNER JOIN dbo.Lv_LineChannel as lc O ...
- leetcode 681. Next Closest Time
Given a time represented in the format "HH:MM", form the next closest time by reusing the ...
- poj 1195 Mobile phones 解题报告
题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...
- html5--6-50 动画效果-变形
html5--6-50 动画效果-变形 实例 学习要点 掌握2D变形动画 了解3D变形动画 transform:2D变形: 通过 CSS3 转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸.转换方 ...
- web 基本概念辨异 —— URI 与 URL
两者的相同点: 都是唯一的,对资源(R:Resource)起到唯一的标识作用: 两者的不同点: URL 是 URI 的子集(URI 是父类,URL 是子类),是一种特定的实现形式: URI 可以是身份 ...
- iOS添加弹出菜单
最近接触的项目需要实现一个弹出窗,类似于点击微信navigation bar右上角的bar button所展现的弹出窗,最终效果如下: Demo代码存放在https://github.com/LuoD ...
- 移动web开发------公用css----自己总结
@charset "utf-8"; html, body { background: #fff; color: #505050; font-size: 10px; -moz-use ...
- py-day15_css+js_初
css+js_初 一.鼠标移动变色 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
- 【旧文章搬运】Windows句柄分配算法(二)
原文发表于百度空间,2009-04-04========================================================================== 在创建句柄 ...