题目:https://www.nowcoder.com/practice/f54d8e6de61e4efb8cce3eebfd0e0daa?tpId=40&tqId=21355&tPage=2&rp=2&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking

C++ 解法

  1. #include <cstdio>
  2. typedef long long LL;
  3. int main(){
  4. LL n, table[1010];
  5. table[0] = 1;
  6. for(int i = 1; i <= 1000; i++){
  7. table[i] = table[i - 1] * i;
  8. }
  9. while(scanf("%lld", &n) != EOF){
  10. printf("%lld\n", table[n]);
  11. }
  12. }

JAVA解法

  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6. while (scanner.hasNext()){
  7. int n = scanner.nextInt();
  8. BigInteger i = new BigInteger("1");
  9. for (int j = 1; j <= n; j++) i=i.multiply(new BigInteger(String.valueOf(j)));
  10. System.out.println(i);
  11. }
  12. }
  13. }