Feli的生日礼物
Problem
Felicia的生日是11月1日(和Kitty是同一天生的哦)。于是Feli请来Kitty一起过生日。Kitty带来了最新款的“Kitty猫”玩具准备送给Feli,不过她说,这份礼物可不是白送的。Feli要帮她一个忙,才能够得到心仪已久的玩具。 Kitty说,“Kitty猫”玩具已经卖出了n!个,n<=10^100 *_*,Kitty想知道确切的数字,而不是无聊的“一个数加个感叹号”。 Feli听了大吃一惊。要知道,算出n!是一个无比艰巨的任务。Feli告诉Kitty,就算Feli算出n!,Kitty也看不下去,因为当n=20时,计算机的长整型已经存不下了(Kitty只能接受1-9之间的数字)。于是Kitty说,你只要告诉我n!最后一位非0的数就可以了。Feli想了想,立刻动手写了个程序算出了正确的答案。现在,请你也试试看!注意哦,AC的男生将会得到一个“Hello Kitty”计算器(可编程,CPU 1THz,Mem 1TMB),AC的女生将会得到一个仿真“Hello Kitty”宠物(善解人意,无须喂养,智商1101,附带写情书功能)。
Input
每行一个n,直到输入数据结束
Output
对应输入的n,每行输出一个答案
Sample Input
1101
Sample Output
8
来源:编程爱好者
import java.util.Scanner; import mail.co_Mail; /** * * @author frostbelt */ public class Main { /** * @param args the command line arguments */ public Main(){ System.out.println( "请输入n:" ); Scanner input= new Scanner(System.in); int n=input.nextInt(); System.out.println( this .getNfactorial_N0(n)); } public static void main(String[] args) { // TODO code application logic here new Main(); } //求n!的最末位非零数字 public int getNfactorial_N0( int n){ int result= 1 ; for ( int i= 1 ;i<=n;i++){ result*=i; while (result% 10 == 0 ){ result/= 10 ; } result=result% 10 ; } return result; } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步