1083. factorials!!!
Time limit:1.0 Second
Memory limit:64 MB
Definition 1.
N!! ...! =
N(
N?
k)(
N? 2
k)... (
NMoD
k), if
kdoesn ' t divide
N;
N!! ...! =
N(
N?
k)(
N? 2
k)...
k, if
kDivides
N(There is
kMarks! In the both cases).
Definition 2.
XMoD
Y-A remainder after division of
XBy
Y. For example, mod 3 = 1; 3! = 3 2 • 1; Ten!!! = 10 7 4 1.given numbers
Nand
kWe have calculated a value of the expression in the first definition. Can do it as well? Inputcontains the only Line:one integer
N, 1≤
N≤10, then exactly one space, then
kExclamation marks, 1≤
k≤20.outputcontains One number-
N!! ...! (There is
kMarks! here). Sample
problem Author:Oleg Katz
problem Source:The 3rd High School children Programming contest, USU, Yekaterinburg, Russia, March 4, 2001
Analysis: Directly according to the definition of the topic can be calculated.
AC Code:
#include <bits/stdc++.h>using namespace Std;int main () { int n; string S; while (~SCANF ("%d", &n)) { cin>>s; int k = S.size (); int ans = 1; if (n% k) { int t = n/k; for (int i=0; i<=t; i++) { ans *= (n-i * k); } } else{ int t = n/k-1; for (int i=0; i<=t; i++) { ans *= (n-i * k); } } printf ("%d\n", ans); } return 0;}
URAL 1083. Factorials!!! (Reading comprehension)