uva 568(数学)
2014-07-17 18:58
232 查看
题解:从1开始乘到n,因为结果只要最后一位,所以每乘完一次,只要保留后5位(少了值会不准确,刚开始只保留了一位,结果到15就错了,保留多了int会溢出,比如3125就会出错) 和下一个数相乘,接着保留5位,注意5位没有后导零,最后取5位中最后一个不是零的就可以了。
#include <iostream> #include <cstdio> 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; }
相关文章推荐
- uva 568(数学)
- *UVALive 6657 - GCD XOR(数学)
- UVA - 10883 (数学——二项式应用)
- uva1639(数学期望,利用对数减少浮点类型数据的精度损失方法)
- 数学专项counting:UVa 417
- uva 11401 数学
- 【组合数学】Critical Mass, UVa580
- UVA 568-Just the Facts
- UVA 11461 - Square Numbers 数学水题
- uva568(数论)
- UVa 11609 Teams (组合数学)
- UVA 10976 Fractions Again?(枚举+数学)
- UVa 10773 Back to Intermediate Math (数学&速度的分解&陷阱)
- UVALive 7511 Multiplication Table (数学模拟题)
- UVa 11427 Expect the Expected (数学期望 + 概率DP)
- 数学,计数(数三角形,uva 11401)
- uva 10014 Simple calculations(数学推导)
- 数学专项number_theory:UVa 756
- UVA 10325 The Lottery (组合数学,容斥原理,二进制枚举)
- uva 568 Just the Facts