URAL 1083. Factorials!!! (Reading comprehension)

Source: Internet
Author: User

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
input Output
9!!
945
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.