首爾性愛美術館18禁的藝術三星平板★瘋殺5290起攝影界美人正妹指定相機款黃國昌嗆周祝瑛 教室一...
2013-07-02 10:37:06 人氣(67) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA] 962 - Taxicab Numbers

0
收藏
0
推薦

TAXICAB NUMBERS


Problem

The famous mathematician Hardy relates the following episode with the (now also famous) Indian mathematician Ramanujan:

I remember once going to see him when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavorable omen. "No," he replied, "it is a very interesting number; it is the smallest number expressible as the sum of two positive cubes in two different ways."

Your objective is to print cab numbers in a given range, [$n1$; $n1$+$rg$], specified by its lower limit, $n1$, and the size of the interval, $rg$. A number is a cab number if it can be expressed as the sum of two positive cubes, in at least two different ways.

Input

Input contains several test cases. For each test case, you are given two numbers in two rows, the lower limit $n1$ and the range we are interested in, $rg$. The lower limit is between 1 and 1000000000 (1E+9). The range is between 1 and 100000. EOF indicates the end of the input.

Output

For each test case, you should output a list of cab numbers, in the specified range. The numbers should be separated by newlines. If there is no cab number in the range, you should output one single line with the word None.

Sample Input

1000
20000

Sample Output

1729
4104
13832
20683

題目描述:
找到區間內所有可以用兩種不同方式(i*i*i + j*j*j) 組成 N。

總之建表


#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int i, j, k;
map<int, int> R;
for(i = 0; i*i*i <= 1000000000; i++) {
for(j = i; ; j++) {
k = i*i*i + j*j*j;
if(k > 1000000000) break;
R[k]++;
}
}
vector<int> V;
for(map<int, int>::iterator it = R.begin();
it != R.end(); it++) {
if(it->second > 1)
V.push_back(it->first);
}
int l, r;
while(scanf("%d %d", &l, &r) == 2) {
r += l;
int x = lower_bound(V.begin(), V.end(), l) - V.begin();
int flag = 0;
for(; x < V.size(); x++) {
if(V[x] > r) break;
printf("%d\n", V[x]), flag = 1;
}
if(!flag)
puts("None");
}
return 0;
}
 

962Taxicab Numbers
台長:Morris
人氣(67) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 434 - Matty's Blocks
此分類上一篇:[UVA] 957 - Popes

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文