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

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

首页休闲益智数学立方更新时间:2024-07-04

对于任一正整数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-

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved