time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:2109
Resolution:901
-
-
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
It means that a number can be used to sum the factorial of some number.
Because the specified number is within 1,000,000, it can be enumerated directly.
//asimple#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cctype>#include<cstdlib>#include<stack>#include<cmath>#include<map>#include<string>#include<queue>#defineINF 100000using namespacestd;Const intMAXN = One; typedefLong Longll;intN;intA[MAXN];intMain () {a[0] =1; for(intI=1; i<maxn; i++) {A[i]= i * a[i-1]; } while(~SCANF ("%d",&N)) { for(inti=maxn-1; i>=0; i--){ if(N >=A[i]) {N-=A[i]; }} printf (n==0?"yes\n":"no\n"); } return 0;}
Topic of 19 degrees per day 1038:sum of factorials