100c之39:年龄问题
2013-06-27 19:39
197 查看
Table of Contents
1 问题2 分析
3 程序
4 输出
问题
张三,李四,王五,刘六年龄是个等差数列。他们四个年龄相加为26,相乘是880,求以他们年龄前四项的等差数列的前20项。分析
穷举程序
1: /** 2: * @file 039c.c 3: * @author Chaolong Zhang <emacsun@163.com> 4: * @date Thu Jun 27 19:16:40 2013 5: * 6: * @brief 张三,李四,王五,刘六年龄是个等差数列。他们四个年龄相加为26,相乘是880,求以他们年龄前四项的等差数列的前20项。 7: * 8: * 9: */ 10: 11: #include <stdio.h> 12: 13: int main(int argc, char *argv[]) 14: { 15: int i,j,k,l; 16: 17: for (i=1; i < 880; ++i) 18: { 19: for (j=1; j < 880/i; ++j) 20: { 21: k=j+j-i; 22: l=k+j-i; 23: if( ( l-k == j-i ) && ( i*j*k*l ==880 ) ){ 24: printf ("%d*%d*%d*%d=880\n",i,j,k,l); 25: } 26: } 27: } 28: return 0; 29: }
输出
2*5*8*11=880 11*8*5*2=880
相关文章推荐
- C++/C经典算法百题--(39-42)年龄几何,三色球问题,两个正整数的最大公约数和(GCD)和最小公倍数(LCM)
- UVA - 167 The Sultan's Successors(回溯 八皇后问题改编)
- 关于dbunit报Duplicate entry '????' for key 'xxx'错误的问题
- 复制Android Studio 工程到其它电脑后遇到The SDK directory 'XXXX‘ does not exist.问题的解决方法
- Unity导入包遇到Error while importing package: Couldn't decompress package 的问题
- java.lang.UnstatisfiedLinkError conldn't find xx.so 问题
- MySQL远程连接ERROR 2003 (HY000):Can't connect to MySQL server on'XXXXX'(111) 的问题
- 解决#1289 - The \'InnoDB\' feature is disabled; you need MySQL built with \'InnoDB\' to have it working的问题
- [IIS问题类]Service Unavailable错误,'DefaultAppPool' 相关,(应用程序池 'DefaultAppPool' 被自动禁用,原因是为此应用程序池提供服务的进程中出现一系列错误)
- cygwin $'\r': command not found问题
- 关于报错unknown character '0xa1'的问题
- 编译错误问题(GDI)"": Error: A1079E: Unrecognized command line option '--diag_suppress=1,2
- 问题解决:java.sql.SQLException:Value '0000-00-00' can not be represented as java.sql.Date
- C++Builder中关于INDY库的使用 以及一些问题的解决(E2238 Multiple declaration for 'fd_set')
- GEF,EMF,RCP,Eclipse's plugin的几个问题(5) RCP Navigator View project name 为空解决办法
- windows 2003下'NT AUTHORITY/NETWORK SERVICE 权限问题
- asp + Access 常见的数据库访问失败问题 Microsoft JET Database Engine 错误 '80004005' 解决办法
- kmplayer绿色版遇到问题'We strongle recommand you...'
- LUA中Attempt to call a non-callable object或attempt to call field 'new' (a nil value)问题的解决
- ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()'问题