每日一九度之 题目1038:Sum of Factorials

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:2109

解决:901

<dl> <dt> 题目描述: </dt> <dd>

    John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathematics, logic, quantum physics, meteorology, science, computers, and game theory. He was 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 the University of Budapest, His Ph.D. dissertation on set theory was an important contributions to the subject.
    At the age of 20, von Neumann proposed a new definition of ordinal numbers that was universally adopted. While still in his twenties, he made many contributions in both pure and applied mathematics that established him as a mathematician 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 in game theory, and with coauthor Oskar Morgenstern he wrote Theory of Games and Economic Behavior (1944).
    There are 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 you to tell whether or not the number can be expressed by the sum of some factorials.
Well, it is just a piece of case. For a given n, you will check if there are some xi, and let n equal to Σt (上标) i=1(下标) xi! (t≥1, xi≥0, xi = xj <==> i = j)
           t
     即 Σ  xi! (t≥1, xi≥0, xi = xj <==> i = j)
          i=1
    If the answer is yes, say "YES"; otherwise, print out "NO".

</dd> </dl> <dl> <dt> 输入: </dt> <dd>

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

</dd> </dl> <dl> <dt> 输出: </dt> <dd>

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

</dd> </dl> <dl> <dt> 样例输入: </dt> <dd>
9
2
</dd> </dl> <dl> <dt> 样例输出: </dt> <dd>
YES
YES
</dd> </dl>

意思是一个数能不能用一些数的阶乘之和。

因为规定数在1,000,000之内,所以可以直接枚举。

//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <map>
#include <string>
#include <queue>
#define INF 100000
using namespace std;
const int maxn = 11;
typedef long long ll;
int n;
int a[maxn];

int main(){
    a[0] = 1;
    for(int i=1; i<maxn; i++){
        a[i] = i * a[i-1];
    }
    while( ~scanf("%d",&n) ){
        for(int i=maxn-1; i>=0; i--){
            if( n >= a[i] ){
                n -= a[i];
            }
        }
        printf(n==0?"YES\n":"NO\n");
    }
    return 0;
}

 

全部评论

相关推荐

01-02 00:50
三峡大学 Java
程序员牛肉:这简历一出手就离失业不远了。 作为一家公司来讲,我如果要招日常实习生,那我对实习生最基本的要求就是要能干活,毕竟你就待三四个月,谁会留心培养你? 那么除了院校之外,最重要的就是项目和实习了。没有实习的话项目就好好搞。 但是你说你这个项目吧:课程作业管理系统和TMS运输管理系统。这两个基本就和闹着玩差不多。 你作为一个想要应聘Java开发实习生的人,对后端的理解还仅仅停留在:“使用mapper和sql映射”,“使用SQL进行多表调用”,“基于MySQL简历表结构”,“基于Spring boot完成CURD操作”这种玩具上......... 找不到后端实习的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务