Problem Description
Definition 1.
n!!…! =
n(
n−
k)(
n−2
k)…(
n mod
k), if
k doesn’t divide
n;
n!!…! =
n(
n−
k)(
n−2
k)…
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! = 321; 10!!! = 10741.
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).
郁闷,发了半天没成功,解释就不敲了,大家估计都懂。
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
char s[30];
int n,k,t,ans;
while(scanf("%d %s",&n,s)!=EOF)
{
k=strlen(s);
if(n%k==0)
{
for(ans=1;n!=k;n-=k)
ans*=n;
ans*=n;
}
else
{
for(ans=1,t=n%k;n!=t;n-=k)
ans*=n;
ans*=t;
}
printf("%d\n",ans);
}
return 0;
}