3511 - 编程计算(4)
时间限制 : 1 秒
内存限制 : 128 MB
爱因斯坦数学题。爱因斯坦曾出过这样一道数学题:有一条长阶梯,若每步跨2阶,最后剩下1阶;若每步跨3阶,最后剩下2阶;若每步跨5阶,最后剩下4阶;若每步跨6阶,最后剩下5阶;只有每步跨7阶,最后才正好1阶不剩。请问,这条阶梯共有多少阶?
题目输入
无输入
题目输出
输出结果
输入/输出样例
输入格式
no input needed
输出格式
119
C语言解答
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); int x = 0; do{ x++; } while (!(x%2==1 && x%3==2 && x%5==4 && x%6==5 && x%7==0)); printf("%d\n", x); return 0; }
C++解答
#include<stdio.h> int main() { int all,step1 = 2,step2 = 3,step3 = 5,step4 = 6,step5 = 7; for(all = 7;;all++) { if(all%step1 == 1 && all%step2 == 2 && all%step3 == 4 && all%step4 == 5 && all%step5 == 0) { printf("%d\n",all); break; } } return 0; }