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; ...
随机推荐
- [转]GPS NEMA 0183协议
一. NMEA0183标准语句(GPS常用语句) $GPGGA例:$GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000 ...
- UIBarButtonSystemItem 各种款式
- 在docker里查看java进程
先使用命令查看docker的运行进程 docker ps [root@localhost logs]# docker ps CONTAINER ID IMAGE ...
- spring cloud config 属性加解密
首先需要(Java Cryptography Extension (JCE))的支持,下载路径: https://www.oracle.com/technetwork/java/javase/down ...
- 对soc-audio体系snd_soc_machine和snd_soc_dai_link简单理解
ASOC (ALSA system on chip) // 主要为嵌入式系统专门开发的sound管理体系结构[luther.gliethttp].Digital Audio ...
- Typescript 常见写法
一.Typescript 中数组 let list: number[] = [1, 2, 3]; let list: Array<number> = [1, 2, 3];
- YTU 2422: C语言习题 n个数逆序
2422: C语言习题 n个数逆序 时间限制: 1 Sec 内存限制: 128 MB 提交: 150 解决: 96 题目描述 将n(n<20)个数按输入时顺序的逆序排列,用函数实现. 输入 ...
- js split分割字符串成数组
str = "2,2,3,5,6"; //这是一字符串 var strs = new Array(); //定义一数组 strs = str.split("," ...
- Codeforces-707D:Persistent Bookcase (离线处理特殊的可持久化问题&&Bitset)
Recently in school Alina has learned what are the persistent data structures: they are data structur ...
- kali-linux简单学习
一. curl --head 返回操作系统的版本 同样的Xprobe2可以和nmap一起返回操作系统的版本 nmap 直接加域名或者ip地址,比较权威判断操作系统版本,或者服务版本,以及开的端口 nm ...