URL 1083. Factorials !!! (Read and understand), uralfactorials

Source: Internet
Author: User

URL 1083. Factorials !!! (Read and understand), uralfactorials

1083. Factorials !!!
Time limit: 1.0 second
Memory limit: 64 MB
Definition 1. N!!...! = N( NK)( N−2 K)... ( NMod K), If KDoesn' t divide N; N!!...! = N( NK)( N−2 K)... K, If KDivides N(There are KMarks! In the both cases ). Definition 2. XMod Y-A remainder after division XBy Y. For example, 10 mod 3 = 1; 3! = 3 · 2 · 1; 10 !!! = 10 · 7 · 4 · 1. Given numbers NAnd KWe have calculated a value of the expression in the first definition. Can you 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 are 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





Resolution: calculate the value based on the definition in the question.





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;}


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.