博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 568(数学)
阅读量:7251 次
发布时间:2019-06-29

本文共 627 字,大约阅读时间需要 2 分钟。

题解:从1開始乘到n,由于结果仅仅要最后一位。所以每乘完一次,仅仅要保留后5位(少了值会不准确,刚開始仅仅保留了一位。结果到15就错了,保留多了int会溢出,比方3125就会出错) 和下一个数相乘,接着保留5位,注意5位没有后导零,最后取5位中最后一个不是零的就能够了。

#include 
#include
using namespace std;int main() { int n; long int temp; while (scanf("%d", &n) != EOF) { if (n == 0) { printf("%5d -> 1\n", n); continue; } int a = 1; long int temp1; for (int i = 1; i <= n; i++) { temp = (i * a) % 10; if (temp == 0) { temp1 = i * a; while (temp == 0) { temp1 = temp1 / 10; temp = temp1 % 10; } a = temp1 % 100000; } else a = (i * a) % 100000; } printf("%5d -> %ld\n", n, temp); } return 0;}

转载地址:http://xnhbm.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
tensorflow入门简单卷积神经网络
查看>>
我的友情链接
查看>>
the dude 使用教程和一点感觉
查看>>
Spring4+Hibernate4 注解整合配置
查看>>
螺旋数字程序
查看>>
Pyhton 第九章 正则表达式
查看>>
mysql主从配置
查看>>
Jconsole远程监控tomcat 的JVM内存(linux、windows)
查看>>
分布式项目(一)iot-pt
查看>>
JFreeChart开源图表组件在Java开发中的应用(一)
查看>>
使用ZooKeeper ACL特性进行znode控制
查看>>
struts2 跳转类型介绍 result type=chain、dispatcher、redirect(redirect-action)
查看>>
宜春之行
查看>>
我的友情链接
查看>>
Exchange2010 dag 的缷载
查看>>
2011/11/14 1:52 坚持就会胜利
查看>>
oracle概念和术语 建表时的一些参数pctfree initrans maxtrans sto
查看>>
我的友情链接
查看>>
转ApplicationContext的三种实现方式以及在web.xml配置的两种方式
查看>>