查找出租车号码 [英] Finding taxicab Numbers

查看:15
本文介绍了查找出租车号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到第一个 n 个出租车号码.给定一个值 n.我想找到前 n 个出租车号码.出租车是一个可以用不止一种方式表示为两个完美立方体之和的数字.

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.

(请注意,有两个相关但不同的集合称为出租车号码":超过 1 中 2 个立方体的总和方式最小的数字是n 中 2 个正整数立方的总和方式.这个问题是关于前一组的,因为后一组只有前六个成员已知)

(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)

例如:

1^3 + 12^3 = 1729 = 9^3 + 10^3

我想大致了解一下算法或如何解决问题的 C 代码片段.

I 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<=pow(i, 1.0/3); j++) {
          for(k=j+1; k<=pow(i,1.0/3); k++) {
              if(j*j*j+k*k*k == i)
              int_count++;
          }
       }
       if(int_count == 2) {
          count++;
          printf("
Got %d Hardy-Ramanujan numbers %d", count, i);  
       }
       i++;
    }
}

由于 a^3+b^3 = na 应该小于 n^(1/3).

Since a^3+b^3 = n, a should be less than n^(1/3).

这篇关于查找出租车号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆