fjnu 1050 Sum of Factorials

Description

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 contribution 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 Foundations 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 him whether or not the number can be expressed by the sum of some factorials.
Well, it's just a piece of cake. For a given n, you'll check if there are some xi, and let n equal to Σ1<=i<=txi!. (t >=1 1, xi >= 0, xi = xj iff. i = j). If the answer is yes, say "YES"; otherwise, print out "NO".

Input

You will get several non-negative integer n (n <= 1,000,000) from input file. Each one is in a line by itself.
The input is terminated by a line with a negative integer.

Output

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

Sample Input

9
-1

Sample Output

YES

 KEY:这种题很BT,不是很难,就是题目难看了点,他要求一个数是否可以由几个数的阶乘得到,那么由于n的规模不大,11!就够了,这样从11开始减下来,就OK,要注意0;判断0是YES还是NO;

 

#include < iostream >
using   namespace  std;

int  a[ 15 ];

int  fun( int  n)
{
    
if(n<=1return 1;
    
else return n*fun(n-1);
}


void  GetList()
{
    
for(int i=0;i<=11;i++)
        a[i]
=fun(i);
}


int  main()
{
    GetList();
    
int n;
    cin
>>n;
    
while(n>=0)
    
{
        
int i=11;
        
if(n==0) cout<<"NO"<<endl;
        
else 
        
{
            
while(n>=0&&i>=0)
            
{
                
if(n>=a[i]) n=n-a[i];
                i
--;
            }

            
if(n==0) cout<<"YES"<<endl;
            
else cout<<"NO"<<endl;
        }

        cin
>>n;
    }

    
return 0;
}



                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好,以下是一个简单的使用HTML制作类似于"https://www.fjnu.edu.cn/main.htm"网页的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>福建师范大学</title> </head> <body> <header> <h1>福建师范大学</h1> </header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">学校概况</a></li> <li><a href="#">新闻中心</a></li> <li><a href="#">招生就业</a></li> <li><a href="#">校园生活</a></li> <li><a href="#">教学科研</a></li> <li><a href="#">校友服务</a></li> </ul> </nav> <main> <article> <h2>学校简介</h2> <p>福建师范大学创建于1907年,是福建省人民政府与教育部共建高校。学校主要办学特色是师范教育和人文社会科学,具有百年办学历史和深厚的文化底蕴。</p> </article> <section> <h2>新闻动态</h2> <ul> <li><a href="#">福建师范大学2021年迎新工作启动</a></li> <li><a href="#">2021年福建师范大学教师招聘公告</a></li> <li><a href="#">福建师范大学2021年本科招生计划</a></li> </ul> </section> </main> <aside> <h2>联系我们</h2> <p>地址:福建省福州市闽侯县上街镇</p> <p>电话:0591-83442777</p> <p>邮箱:fjnu@fjnu.edu.cn</p> </aside> <footer> <p>© 2021 福建师范大学</p> </footer> </body> </html> ``` 在这个示例中,我们使用HTML5标记语言来创建网页。我们通过`<header>`元素来定义网页的标题,通过`<nav>`元素来定义网页的主要导航,通过`<main>`元素来定义网页的主要内容,通过`<aside>`元素来定义网页的侧边栏内容,通过`<footer>`元素来定义网页的页脚。在`<main>`元素中,我们使用`<article>`元素来定义学校简介部分的内容,使用`<section>`元素来定义新闻动态部分的内容。网页的样式和布局可以通过CSS来实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值