Training Camp(水题)

Problem Statement

Snuke loves working out. He is now exercising N times.

Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.

Find Snuke’s power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10e9+7.

Constraints
  • 1≤N≤10e5
Input
  • The input is given from Standard Input in the following format:

  • N

Output
  • Print the answer modulo 10e9+7.
Sample Input 1
  • 3
Sample Output 1
  • 6

  • After Snuke exercises for the first time, his power gets multipliedby 1 and becomes 1.

  • After Snuke exercises for the second time, hispower gets multipliedby 2 and becomes 2.

  • After Snuke exercises for the third time, his power getsmultiplied by 3 and becomes 6.

Sample Input 2
  • 10
Sample Output 2
  • 3628800
Sample Input 3
  • 100000
Sample Output 3
  • 457992974
  • Print the answer modulo 10e9+7.

题意:求N的阶乘模10^9+7的值.

解析:利用打表方式,求出1-100005(10^5+5)各数值阶乘mod 10e9+7存放到一个数组中,最后输出数组中对应下标为N的值即可

扫描二维码关注公众号,回复: 5061715 查看本文章
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>

using namespace std;

# define mod 1000000007
long long a[100005];

int main()
{
    a[0]= 1;
    long long n;
    for(int i = 1; i < 100005; i++)
        a[i] = a[i-1]*i % mod;

    while(~scanf("%lld",&n))
    {
         cout << a[n] << endl;
    }
    return 0;
}

Thank for you like!

猜你喜欢

转载自blog.csdn.net/qq_41216743/article/details/86633926