打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
趣味数学与编程|任何一个整数的立方都可以写成一串连续奇数的和

对于任一正整数a,不论a 是奇数还是偶数,整数(a×a−a+1)必然为奇数。

构造一个等差数列,数列的首项为(a×a−a+1),等差数列的差值为2(奇数数列),则前a 项的和为:

a× ((a×a−a+1))+2×a(a−1)/2

=a×a×a−a×a+a+a×a−a

=a×a×a

证明过程可知所要求的奇数数列的首项为(a×a−a+1),长度为a。

#include<stdio.h>void vrNico(int a)// 任何一个整数的立方都可以写成一串连续奇数的和{ int b,c,d; b=a*a*a; /*求整数的三次方*/ printf(' >> %d*%d*%d=%d=',a,a,a,b); for(d=0,c=0;c<a;c++) /*输出数列,首项为a*a-a+1,等差值为2*/ { d+=a*a-a+1+c*2; /*求数列的前a项的和*/ printf(c?'+%d':'%d',a*a-a+1+c*2); } if(d==b)printf(' Satisfy!\n'); /*若条件满足则输出'Y'*/ else printf(' Dissatisfy!\n'); /*否则输出'N'*/}void main(){ int n=1; // 尼科彻斯定理,即任何一个整数的立方都可以写成一串连续奇数的和。 puts('******************************************************'); puts('* This program is to verify Theorem of Nicoqish. *'); puts('* That is the cube of any integer can be represented *'); puts('* as the sum of some continue odd numbers. *'); puts('* For example, 8^3=512=57+59+61+63+65+67+69+71. *'); puts('******************************************************'); while(n!=0) { printf(' >> Please input a integer to verify(0 to quit): '); scanf('%d',&n); /*输入任一整数*/ if(n==0) break; printf(' >> ------ Results of verification: ------------\n'); vrNico(n); /*调用函数进行验证*/ printf(' >> ---------------------------------------------\n'); } puts('\n Press any key to quit...'); getchar();}/******************************************************** This program is to verify Theorem of Nicoqish. ** That is the cube of any integer can be represented ** as the sum of some continue odd numbers. ** For example, 8^3=512=57+59+61+63+65+67+69+71. ******************************************************* >> Please input a integer to verify(0 to quit): 5 >> ------ Results of verification: ------------ >> 5*5*5=125=21+23+25+27+29 Satisfy! >> --------------------------------------------- >> Please input a integer to verify(0 to quit):*/

-End-

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
095.奇数平方的有趣性质
2012年11月10日小学四年级奥数题及答案《整数与数列》奥数辅导讲解
输入输出函数及控制流程语句
DSP 调用 C 输入输出函数 scanf() printf() gets() puts() zz
求数列和整数部分
整型变量的输出及溢出|C语言学习
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服