1038.sum of Factorials

Source: Internet
Author: User

Title Description:

John von Neumann, B. Dec, 1903, D. Feb. 8, 1957, was a hungarian-american mathematician who made important contributio NS to the foundations of mathematics, logic, quantum physics, meteorology, science, computers, and game theory. He is noted for a phenomenal memory and the speed with which he absorbed ideas and solved problems. In 1925 he received a B.S. Diploma in Chemical Engineering from Zurich Institute and in 1926 a Ph.D. in Mathematics from T He University of Budapest, he Ph.D. dissertation on set theory is an important contributions to the subject.
At the age of, von Neumann proposed a new definition of ordinal numbers, is universally adopted. While still in the He twenties, he made many contributions in both pure and applied mathematics that established him as a mat Hematician of unusual depth. His mathematical Foundation of Quantum Mechanics (1932) built a, solid framework for the new scientific, discipline.
During This time he also proved the Mini-max theorem of GAME theory. He gradually expanded his work on game theory, and with coauthor Oskar Morgenstern he wrote theory of games and economic B Ehavior (1944).
There is some numbers which can be expressed by the sum of factorials. For example 9, 9 = 1! + 2! + 3!. Dr. von Neumann was very interested in such numbers. So, he gives you a number n, and wants if you are whether or not the number can expressed by the sum of some factorial S.
Well, it's just a piece of case. For a given n, you'll check if there is some XI, and let n equal toσt (superscript) i=1 (subscript) xi! (T≥1, xi≥0, xi = XJ <==> i = j)
T
namely σxi! (T≥1, xi≥0, xi = XJ <==> i = j)
I=1
If The answer is yes, say "yes"; Otherwise, print out "NO".

Input:

You'll get a non-negative integer n (n≤1,000,000) from input file.

Output:

For the N of the input file, you should print exactly one word ("YES" or "NO") in a single line. No extra spaces is allowed.

Sample input:
92
Sample output:
Yesyes

#include <iostream>using namespacestd;intMain () {intf[ One],n; f[0]=1;  for(intI=1;i< One; i++) {F[i]=f[i-1]*i; }     while(cin>>N) {        if(n==0) cout<<"NO"<<Endl; Else {             for(intI=Ten; i>=0; i--){                if(n>=F[i]) n-=F[i]; }            if(n==0) cout<<"YES"<<Endl; Elsecout<<"NO"<<Endl; }    }    return 0;}

1038.sum of Factorials

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.