SDNU 1272.SL的秘密

Description

据说今天是男神SL的生日,但是他很低调,轻轻地送了一道大水题...

就是传说中的 " N !"

Input

每一行包含一个整数N(0 <= N<=10^9).

Output

对于每个数,输出 N! mod 2009

Sample Input

4
5

Sample Output

24
120

Source

思路:这道题有个玄学的地方,那就是2009 = 41*7*7。所以当累乘到了41!时,比它大的数取膜2009后,全都是0
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
using namespace std;
#define ll long long
const int maxn = 5100;

ll n, sum;

ll qsm(ll a)
{
    ll ans = 1;
    for(int i = 1; i <= a; i++)
    {
        ans = ((ans%2009)*(i%2009))%2009;
    }
    return ans;
}

int main()
{
    while(~scanf("%lld", &n))
    {
        if(n<41)
        {
            sum = qsm(n);
            printf("%lld\n", sum);
        }
        else printf("0\n");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/RootVount/p/10994611.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值