题目链接:http://abc055.contest.atcoder.jp/tasks/abc055_b?lang=en
Time limit : 2sec / Memory limit : 256MB
Score : 200 points
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 109+7.
The input is given from Standard Input in the following format:
NPrint the answer modulo 109+7.
Print the answer modulo 109+7.
Submit
题意:求n!(9+7)
解析:直接long long,求下n!,每次乘时%mod即可
代码:
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<vector> #include<queue> #include<map> #include<cmath> #define N 1009 using namespace std; const int INF = 0x3f3f3f3f; typedef unsigned long long LL; const int mod = 1e9 + 7; int main() { LL ans = 1; int n; scanf("%d", &n); for(LL i = 1; i <= n; i++) ans = (ans % mod) * (i % mod) % mod; cout << ans << endl; return 0; }