Nyoj 91 the sum of factorial

Source: Internet
Author: User

Factorial and time limit: Ms | Memory limit: 65535 KB Difficulty: 3
Describe

Give you a non-negative integer n to determine if n is a sum of the factorial of some number (these numbers are not allowed to be reused and are positive), such as 9=1! +2!+3!, if yes, output yes, otherwise output no;

Input
The first line has an integer 0<m<100, which indicates that there is an M group of test data;
Each set of test data has a positive integer n<1000000;
Output
If the condition is met, output yes, otherwise output no;
Sample input
2910
Sample output
YesNo

Note the case of the OUTPUT results!!!!!
#include <stdio.h> #include <math.h>int main () {int n,m,j,i,t,sum;    int a[12];scanf ("%d", &n), while (n--) {sum=1;t=1;for (i=1;i<=10;i++) {for (j=1;j<=i;j++)       ///Because the maximum number is 1 million, The factorial of 10 is greater than 1 million {                       //So the factorial of these numbers to 9 is enough sum*=j;            This loop puts the factorial of 1 to 9 into the array a}a[t]=sum;t++;sum=1;} scanf ("%d", &m), for (i=10;i>=1;i--) {if (M>=a[i]) m=m-a[i];//ask whether to conform to}    if (m==0)    printf ("yes\n");    elseprintf ("no\n"); }return 0;}

  



Nyoj 91 the sum of factorial

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.