4 条题解

  • 1
    @ 2026-1-2 18:40:09

    这道题看似要写for循环,其实math库python自带 于是这道题秒杀:

    
    import math
    
    def calculate_factorial(n):
        return math.factorial(n)
    
    number = int(input())
    result = calculate_factorial(number)
    print(result)
    
    
    
    • 0
      @ 2025-6-8 14:06:08
      #include<bits/stdc++.h> 
      using namespace std;
      int main() {
          int n, s=0, f=1;
          cin>>n;
          for (int i=1;i<=n;++i){
              f*=i;
          }
          cout<<f;
          return 0;
      }
      
      • 0
        @ 2025-4-13 19:40:07
        #include<bits/stdc++.h>
        using namespace std;
        int main(){
            long long n;
            cin>>n;
            long long y=1,u=1;
            for(int i=1;i<=n;i++){
                u=u*y;
                y++;
            }
            cout<<u;
            return 0;
        }
        
        • 0
          @ 2024-12-22 11:03:57

          C++ :

          #include <cstdio>
          using namespace std;
          int main ()
          {
          	long long s;		//long long的范围为-263~263-1,
          					    //int的-1019~1019略窄
          	int n;				//n不能定义为long long,否则for语句死循环
          	s=1;
          	scanf("%d",&n);
          	for (int i=1; i<=n ; ++i)	//当n=13时s超出long int的范围
          		s*=i;
          	printf("%lld\n",s);		//使用%d输出long long结果有误
          	return 0;
          }
          
          

          Python :

          # coding=utf-8
          s = int(input())
          for i in range(1,s,1):
              s=s*i
          print(s)
          
          • 1

          信息

          ID
          124
          时间
          1000ms
          内存
          128MiB
          难度
          1
          标签
          (无)
          递交数
          16
          已通过
          52
          上传者