查找第一个 N 出租车数量。给定值 N 。我想找到的前n出租车数量。 甲出租车是一个数字,可以是pssed作为两种完美立方体在一个以上的方式总和前$ P $
(注意,有两个相关但不同的被称为套 出租车数量:2个立方体在款项的超过1 这样和这是最小的数字 在2正整数立方之和 N 方法的。这个问题是关于前集, 因为后者集具有唯一已知的前六个成员)
例如:
1 ^ 3 + 12 ^ 3 = 1729 = 9 ^ 3 + 10 ^ 3
我想算法的粗略概述,或如何解决这个问题的C代码片段。
的前五项分别是: I J K L数量 --------------------------------- 1 12 9 10 1729 2 16 9 15 4104 2 24 18 20 13832 10 27 19 24 20683 4 32 18 30 32832解决方案
我想出答案可以得到这样的:
#包括< stdio.h中> 诠释的main(){ INT N,I,计数= 0,J,K,int_count; 输出(输入所需值的数目:); scanf函数(%d个,和放大器; N); I = 1; 而(计数n种){ int_count = 0; 为(J = 1; J&其中; =((中间体(POW(ⅰ,1.0 / 3)); J ++){ 为(K = J + 1; K&其中; =((中间体(POW(ⅰ,1.0 / 3)); k ++){ 如果(j *Ĵ* J + K * K *满足K == I) int_count ++; } } 如果(int_count == 2){ 算上++; 的printf(\ nGot%D哈代 - 拉马努金人数%D,算我); } 我++; } }
由于 A ^ 3 + B ^ 3 = N , A 应小于ñ^(1/3)。
Find the first n taxicab numbers. Given a value n. I would like to find the first n taxicab numbers. A taxicab being a number that can be expressed as the sum of two perfect cubes in more than one way.
(Note that there are two related but different sets referred to as 'taxicab numbers': the sums of 2 cubes in more than 1 way, and the smallest numbers that are the sum of 2 positive integral cubes in n ways. This question is about the former set, since the latter set has only the first six members known)
For example:
1^3 + 12^3 = 1729 = 9^3 + 10^3I would like a rough overview of the algorithm or the C snippet of how to approach the problem.
The first five of these are: I J K L Number --------------------------------- 1 12 9 10 1729 2 16 9 15 4104 2 24 18 20 13832 10 27 19 24 20683 4 32 18 30 32832解决方案
I figured out the answer could be obtained this way:
#include<stdio.h> int main() { int n, i, count=0, j, k, int_count; printf("Enter the number of values needed: "); scanf("%d", &n); i = 1; while(count < n) { int_count = 0; for (j=1; j<=((int(pow(i, 1.0/3)); j++) { for(k=j+1; k<=((int(pow(i,1.0/3)); k++) { if(j*j*j+k*k*k == i) int_count++; } } if(int_count == 2) { count++; printf("\nGot %d Hardy-Ramanujan numbers %d", count, i); } i++; } }Since a^3+b^3 = n, a should be less than n^(1/3).
更多推荐
寻找出租车号码
发布评论