Topic 1038:sum of Factorials
time limit:1 seconds
Memory limit:32 MB
Special question: No
submitted:1491
Resolution:635
-
-
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
Test instructions: If the given number n can be represented as a factorial sequence of numbers, such as 9 = 1! + 2! + 3! , the output is yes, otherwise the output is no. |
#include <stdio.h>int n;int factorial[10]={1,1,2,6,24,120,720,5040,40320,362880};//due to factorial[n] than sum ( Factorial[0 to n]) is big, so just reduce it. int check (int n) { if (n==0) { printf ("no\n"); } for (int i=9;i>=0;--i) if (N>=factorial[i]) n-=factorial[i]; if (n==0) printf ("yes\n"); else printf ("no\n");} int main (int argc, char *argv[]) { freopen ("1038.in", "R", stdin); while (~SCANF ("%d", &n)) { check (n); } return 0;}
Nine degrees OJ 1038 Sum of factorials (analog)