Perfect Cubes
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 12581 Accepted: 6697
Description
For hundreds of years Fermat's Last Theorem, which stated simply that for n > 2 there exist no integers a, b, c > 1 such that a^n = b^n + c^n, has remained elusively unproven. (A recent proof is believed to be correct, though it is still undergoing scrutiny.) It is possible, however, to find integers greater than 1 that satisfy the "perfect cube" equation a^3 = b^3 + c^3 + d^3 (e.g. a quick calculation will show that the equation 12^3 = 6^3 + 8^3 + 10^3 is indeed true). This problem requires that you write a program to find all sets of numbers {a,b,c,d} which satisfy this equation for a <= N.
Input
One integer N (N <= 100).
Output
The output should be listed as shown below, one perfect cube per line, in non-decreasing order of a (i.e. the lines should be sorted by their a values). The values of b, c, and d should also be listed in non-decreasing order on the line itself. There do exist several values of a which can be produced from multiple distinct sets of b, c, and d triples. In these cases, the triples with the smaller b values should be listed first.
Sample Input
24Sample Output
Cube = 6, Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
Cube = 18, Triple = (9,12,15)
Cube = 19, Triple = (3,10,18)
Cube = 20, Triple = (7,14,17)
Cube = 24, Triple = (12,16,20)Source
Mid-Central USA 1995
问输入n n<=100 在n之内包括n的范围内找一个a 使得a的三次方等于bcd三者的三次方的和 如果存在 这样的a 按照a从小到大输出 对于a相同的 按照b从小到大输出
另外 Triple内输入要遵循不递减的顺序
打表用代码 内存超出了 MLE ac的打表代码 在最下面
#include#include using namespace std; struct haha { int b,c,d; friend bool operator< (struct haha ai,const struct haha bi) { return ai.b ss[1000000+5]; int main() { int n,i,j,k; int b[100]; for(i=1;i<=100;i++) { b[i]=i*i*i; hash[i*i*i]=i;} for(i=2;i<=100;i++) for(j=i+1;b[j]+b[i]<=1000000;j++) { for(k=j+1;b[i]+b[j]+b[k]<=1000000;k++) { int mid; mid=b[i]+b[j]+b[k]; mid=hash[mid]; if(mid==0) continue; q.b=i;q.c=j;q.d=k; ss[mid].insert(q); } } set ::iterator it; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { if(!ss[i].empty()) for(it=ss[i].begin();it!=ss[i].end();it++) printf("Cube = %d, Triple = (%d,%d,%d)\n",i,it->b,it->c,it->d); } } return 0; }
#include#include using namespace std; struct haha { int b,c,d,id; }q[100]; int main() { q[0].id=6;q[0].b=3;q[0].c=4;q[0].d=5; q[1].id=12,q[1].b=6,q[1].c=8,q[1].d=10; q[2].id=18,q[2].b=2,q[2].c=12,q[2].d=16; q[3].id=18,q[3].b=9,q[3].c=12,q[3].d=15; q[4].id=19,q[4].b=3,q[4].c=10,q[4].d=18; q[5].id=20,q[5].b=7,q[5].c=14,q[5].d=17; q[6].id=24,q[6].b=12,q[6].c=16,q[6].d=20; q[7].id=25,q[7].b=4,q[7].c=17,q[7].d=22; q[8].id=27,q[8].b=3,q[8].c=18,q[8].d=24; q[9].id=28,q[9].b=18,q[9].c=19,q[9].d=21; q[10].id=29,q[10].b=11,q[10].c=15,q[10].d=27; q[11].id=30,q[11].b=15,q[11].c=20,q[11].d=25; q[12].id=36,q[12].b=4,q[12].c=24,q[12].d=32; q[13].id=36,q[13].b=18,q[13].c=24,q[13].d=30; q[14].id=38,q[14].b=6,q[14].c=20,q[14].d=36; q[15].id=40,q[15].b=14,q[15].c=28,q[15].d=34; q[16].id=41,q[16].b=2,q[16].c=17,q[16].d=40; q[17].id=41,q[17].b=6,q[17].c=32,q[17].d=33; q[18].id=42,q[18].b=21,q[18].c=28,q[18].d=35; q[19].id=44,q[19].b=16,q[19].c=23,q[19].d=41; q[20].id=45,q[20].b=5,q[20].c=30,q[20].d=40; q[21].id=46,q[21].b=3,q[21].c=36,q[21].d=37; q[22].id=46,q[22].b=27,q[22].c=30,q[22].d=37; q[23].id=48,q[23].b=24,q[23].c=32,q[23].d=40; q[24].id=50,q[24].b=8,q[24].c=34,q[24].d=44; q[25].id=53,q[25].b=29,q[25].c=34,q[25].d=44; q[26].id=54,q[26].b=6,q[26].c=36,q[26].d=48; q[27].id=54,q[27].b=12,q[27].c=19,q[27].d=53; q[28].id=54,q[28].b=27,q[28].c=36,q[28].d=45; q[29].id=56,q[29].b=36,q[29].c=38,q[29].d=42; q[30].id=57,q[30].b=9,q[30].c=30,q[30].d=54; q[31].id=58,q[31].b=15,q[31].c=42,q