2016-04-08 Problem Solving►UVa UVa 11428 - Cubes Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 $N = x^3 - y^3$ ,給 $N$ 求 $x$ 和 $y$ ,若有多組解,$y$ 小的優先。 Solution$60^3 - 59^3 \gt 10000$ ,所以建表建到 59 即可,一邊記下所用的 x 和 y。 CodeUVa 11428UVa 11428 - Cubes1234567891011121314151617181920212223242526272829303132#include<cstdio>#define N 10001int main(){ //60 * 60 * 60 - 59 * 59 * 59 超過10000了 int x[N] = {}, y[N] = {}, n; bool isOk[N] = {}; for (int i = 2; i < 60; i++) { int iii = i*i*i; for (int j = 1; j < i; j++) { n = iii - j*j*j; if (n <= 10000 && !isOk[n]) { isOk[n] = true; x[n] = i; y[n] = j; } } } while (scanf("%d", &n) && n) { if (isOk[n]) printf("%d %d\n", x[n], y[n]); else puts("No solution"); } return 0;} Newer UVa 10026 - Shoemaker's Problem Older UVa 990 - Diving for Gold