主题:[讨论]有兴趣不妨来看看
最近看到一道题,想拿出来分享
阶乘末尾非0数字
【问题描述】:输入N,输出N!的最后一位非0的数字。例如,输入:1000 输出:2
【数值范围】100<=N<=10000000000
这道题呢,我研究过程序如下:
OPEN "NOTZERO.IN" FOR INPUT AS #1
OPEN "NOTZERO.OUT" FOR OUTPUT AS #2
DEFDBL A-Z
INPUT #1, N: X = 1
FOR I = 2 TO N: T = I
WHILE T - INT(T / 10) * 10 = 0: T = INT(T / 10): WEND
T = VAL(RIGHT$(LTRIM$(STR$(T)), 5))
X = X * T
WHILE X - INT(X / 10) * 10 = 0: X = INT(X / 10): WEND
X = VAL(RIGHT$(LTRIM$(STR$(X)), 5))
NEXT I
PRINT #2, VAL(RIGHT$(LTRIM$(STR$(X)), 1))
END
此题可能还会有些不足之处,请大家点评,如果有兴趣,请各位也写一下,我会加分滴.
阶乘末尾非0数字
【问题描述】:输入N,输出N!的最后一位非0的数字。例如,输入:1000 输出:2
【数值范围】100<=N<=10000000000
这道题呢,我研究过程序如下:
OPEN "NOTZERO.IN" FOR INPUT AS #1
OPEN "NOTZERO.OUT" FOR OUTPUT AS #2
DEFDBL A-Z
INPUT #1, N: X = 1
FOR I = 2 TO N: T = I
WHILE T - INT(T / 10) * 10 = 0: T = INT(T / 10): WEND
T = VAL(RIGHT$(LTRIM$(STR$(T)), 5))
X = X * T
WHILE X - INT(X / 10) * 10 = 0: X = INT(X / 10): WEND
X = VAL(RIGHT$(LTRIM$(STR$(X)), 5))
NEXT I
PRINT #2, VAL(RIGHT$(LTRIM$(STR$(X)), 1))
END
此题可能还会有些不足之处,请大家点评,如果有兴趣,请各位也写一下,我会加分滴.