/**
大意: 求A(n,m)的结果中从左到右第一个非零数
思路: 0是由2*5的得到的,所以将n!中的2,5约掉可得(2的数目比5多,最后再考虑进去即可)
那n!中2 的个数怎么求呢?
int get2(int n){
if(n==0)
return 0;
return n/2+get2(n/2);
}
eg: 1*2*3*4*5*6*7*8*9*10 约去2,5可得,,1*1*3*1*1*3*7*1*9*1
所以最后肯定是3,7,9.。的数列,,那么在最后的数列中3,7,9,有多少个呢?
可以这样考虑: 1,2,3,4,5,6,7,8,9,10 可以分为奇偶数列 即 1,3,5,7,9 2,4,6,8,10===>2*(1,2,3,4,5)
这就出现了递归,,g(n) = g(n/2)+f(n) { f(n)为奇数列 }
那在奇数列中怎么找3,7,9 的个数呢?
1,3,5,7,9,11,13,15,17,19 有可以再分 1,3,7,9,11,13,17,19 ///5,15,25 ====〉5*(1,3,5)
这里有出现了递归,,f(n,x) = n/10 + (n%10>=x) + f(n/5,x)
**/ #include <iostream>
using namespace std; int s[][]={
{,,,},{,,,},{,,,},{,,,}
};
int get2(int n){
if(n==)
return ;
return n/+get2(n/);
} int get5(int n){
if(n==)
return ;
return n/+get5(n/);
} int get(int n,int x){
if(n==)
return ;
return n/+(n%>=x)+get(n/,x);
} int getx(int n,int x){
if(n==)
return ;
int res =;
res = getx(n/,x)+get(n,x);
return res;
} int main()
{
int n,m;
while(cin>>n>>m){
int num2 = get2(n)-get2(n-m);
int num5 = get5(n)-get5(n-m);
int num3 = getx(n,)-getx(n-m,);
int num7 = getx(n,)-getx(n-m,);
int num9 = getx(n,)-getx(n-m,);
if(num2<num5){
cout<<<<endl;
continue;
}else{
int res =;
if(num2!=num5){
num2 = num2-num5;
res = res*s[][num2%];
res = res%;
}
res *= s[][num3%];
res %=;
res *= s[][num7%];
res %=;
res *= s[][num9%];
res = res%;
cout<<res<<endl;
}
}
return ;
}

poj 1150 The Last Non-zero Digit的更多相关文章

  1. POJ 1150 The Last Non-zero Digit 数论+容斥

    POJ 1150 The Last Non-zero Digit 数论+容斥 题目地址: id=1150" rel="nofollow" style="colo ...

  2. #数论-模运算#POJ 1150、1284、2115

    1.POJ 1150 The Last Non-zero Digit #质因数分解+模运算分治# 先贴两份题解: http://www.hankcs.com/program/algorithm/poj ...

  3. 最后一个非零数字(POJ 1604、POJ 1150、POJ 3406)

    POJ中有些问题给出了一个长数字序列(即序列中的数字非常多),这个长数字序列的生成有一定的规律,要求求出这个长数字序列中某个位上的数字是多少.这种问题通过分析,找出规律就容易解决. 例如,N!是一个非 ...

  4. Codeforces Round #449 (Div. 2) B. Chtholly's request【偶数位回文数】

    B. Chtholly's request time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. POJ 3187 Backward Digit Sums 枚举水~

    POJ 3187  Backward Digit Sums http://poj.org/problem?id=3187 题目大意: 给你一个原始的数字序列: 3   1   2   4  他可以相邻 ...

  6. Backward Digit Sums(POJ 3187)

    Backward Digit Sums Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5495   Accepted: 31 ...

  7. 穷竭搜索:POJ 3187 Backward Digit Sums

    题目:http://poj.org/problem?id=3187 题意: 像这样,输入N : 表示层数,输入over表示最后一层的数字,然后这是一个杨辉三角,根据这个公式,由最后一层的数,推出第一行 ...

  8. 【POJ - 3187】Backward Digit Sums(搜索)

    -->Backward Digit Sums 直接写中文了 Descriptions: FJ 和 他的奶牛们在玩一个心理游戏.他们以某种方式写下1至N的数字(1<=N<=10). 然 ...

  9. Enum:Backward Digit Sums(POJ 3187)

    反过来推 题目大意:就是农夫和这只牛又杠上了(怎么老是牛啊,能换点花样吗),给出一行数(从1到N),按杨辉三角的形式叠加到最后,可以得到一个数,现在反过来问你,如果我给你这个数,你找出一开始的序列(可 ...

随机推荐

  1. hdoj 2620 Bone Collector(0-1背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 思路分析:该问题为经典的0-1背包问题:假设状态dp[i][v]表示前i件物品恰放入一个容量为v ...

  2. MRC下单例模式的内存问题与ARC实现

    单例模式保证一个类只能拥有一个静态的实例,类负责创建与维护这个实例,并提供一个统一的静态(类方法)访问方式,并封锁了这个类外部的代码对这个类对象的创建. .h文件: #import <Found ...

  3. 解决android加载图片时内存溢出问题

    尽量不要使用setImageBitmap或setImageResource或BitmapFactory.decodeResource来设置一张大图,因为这些函数在完成decode后,最终都是通过jav ...

  4. linux搭建邮件服务器

    一.概述: 在配置邮件服务器之前,先解释几个概念. 通常使用Email都很容易,但是Internet的邮件系统是通过几个复杂的部分连接而成的,对于最终用户而言,我们熟悉的Outlook,Foxmail ...

  5. linux中时间函数

    linux下常用时间类型有四种: time_t . struct   tm. struct  timeval .    struct   timespec 1.time_t   时间函数 time_t ...

  6. 用JavaScript判断横屏竖屏问题

    判断手机横竖屏状态: //判断手机横竖屏状态: function hengshuping() { if(window.orientation == 180 || window.orientation= ...

  7. WINFORM Tootip使用小结

    toolTip1.Active = true;   //激活工具提示,只有激活才会显示提示 toolTip1.IsBalloon = true;    //toolTip以气泡形式出现 toolTip ...

  8. Auto-Layout 的各种坑Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'

    我们的很多人现在都在使用autolayout,用着也是非常爽但是有了这个东西以后更爽 很省事,什么都不用自己搞.Xcode完全搞定了,但是我终于为自己的懒惰付出了代价,再iphone4怎么运行怎么cr ...

  9. css布局之块上下左右居中

    以下方案的通用代码: HTML code: <div class="box"> <div class="content"> <!- ...

  10. ActiveMQ下载及安装

    1.下载ActiveMQ 官方网站:http://activemq.apache.org/ 根据需要下载不同的版本.我下载的是5.13.3-win64的版本 2.运行ActiveMQ服务 2.1解压缩 ...