24h購物| | PChome| 登入
2012-04-13 17:20:47| 人氣1,988| 回應0 | 上一篇 | 下一篇

[UVA][Math] 11428 - Cubes

推薦 0 收藏 0 轉貼0 訂閱站台

Problem B
Cubes
Input: Standard Input

Output: Standard Output

 

 

Given a positive integer N you will have to find two positive integers x and y such that:

 

 

Input

The input file contains at most 10o lines of inputs. Each line contains a positive integer N (0<N≤10000). Input is terminated by a line containing a single zero. This line should not be processed.

 

Output

For each line of input produce one or more lines of output. Each of these lines contains two positive integers x, y separated by a single space, such that. If there is no such integer values of x and y then produce the line “No solution” instead. If there is more than one solution then output the one with smallest value of y.

 

Sample Input                           Output for Sample Input

7

37

12

0

 

2 1

4 3

No solution

 


Problemsetter: Shahriar Manzoor

Special Thanks: Derek Kisman


做法 : 建表
很明顯的會發現 59^3 - 58^3 已經是極限了,
而如果 x 的範圍再大的話, 則 y 不管怎樣, 都會超出範圍

#include <stdio.h>

int main() {
    int i, j;
    int x[10001], y[10001];
    int hasAns[10001] = {};
    for(i = 2; i <= 60; i++) {
        for(j = i-1; j >= 1; j--) {
            if(i*i*i - j*j*j <= 10000 && hasAns[i*i*i - j*j*j] == 0) {
                hasAns[i*i*i - j*j*j] = 1;
                x[i*i*i - j*j*j] = i;
                y[i*i*i - j*j*j] = j;
            }
        }
    }
    int n;
    while(scanf("%d", &n) == 1 && n) {
        if(hasAns[n])
            printf("%d %d\n", x[n], y[n]);
        else
            puts("No solution");
    }
    return 0;
}

台長: Morris
人氣(1,988) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][DP] 12063 - Zeros and Ones
此分類上一篇:[UVA][SPFA&DP][C++] 11813 - Shopping

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文