hdu2674 N!Again---思维
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=2674
题目大意:
求n!%2009的值
思路:
由于模2009,所以大于等于2009的直接为0,前2009位打表
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<set> 6 #include<cmath> 7 using namespace std; 8 const int maxn = 1e4 + 10; 9 typedef long long ll; 10 ll T, n, m; 11 ll a[maxn]; 12 int main() 13 { 14 a[0] = 1; 15 for(int i = 1; i <= 2009; i++) 16 { 17 a[i] = a[i - 1] * i % 2009; 18 } 19 while(cin >> n) 20 { 21 if(n >= 2009)cout<<"0"<<endl; 22 else cout<<a[n]<<endl; 23 } 24 return 0; 25 }
越努力,越幸运