Ural-1083. Factorials!!!(水题)

1083. Factorials!!!

Time limit: 1.0 second Memory limit: 64 MB
Definition 1. n!!…! = n(nk)(n−2k)…(n mod k), if k doesn’t divide nn!!…! = n(nk)(n−2k)…k, if k divides n (There are k marks ! in the both cases).
Definition 2. X mod Y — a remainder after division of X by Y.
For example, 10 mod 3 = 1; 3! = 3·2·1; 10!!! = 10·7·4·1.
Given numbers n and k we have calculated a value of the expression in the first definition. Can you do it as well?

Input

contains the only line: one integer n, 1 ≤ n ≤ 10, then exactly one space, then k exclamation marks, 1 ≤ k ≤ 20.

Output

contains one number — n!!…! (there are k marks ! here).

Sample

inputoutput
9 !!
945


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
int n,k,ans;
char ch[30];
int main()
{
//    freopen("in.txt","r",stdin);
    while(scanf("%d%s",&n,ch)!=EOF)
    {
        ans = 1;
        k = strlen(ch);
        int i;
        if(n%k)
        {
            for(i=n;i>k;i-=k)
            {
                ans *= i;
            }
            ans *= i;
        }
        else
        {
            for(i=n;i>=k;i-=k)
            {
                ans *= i;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值