1. 程式人生 > >Keep Fighting All The Time

Keep Fighting All The Time

            著名的愛因斯坦階梯問題是這樣的:有一條長長長的階梯,,如果你每步跨2階,那麼最後剩1階;如果你每步跨3階,那麼最後剩2階;如果你每步跨5階,那麼最後剩4階;如果你每步跨6階,那麼最後剩5階;最有當你每步跨7階時,最後正好走完,一階也不剩。請問這條階梯最少有多少階。

       從題目條件:“如果你每步跨2階,那麼最後剩1階;如果你每步跨3階,那麼最後剩2階;如果你每步跨5階,那麼最後剩4階;如果你每步跨6階,那麼最後剩5階;最有當你每步跨7階時,最後正好走完,一階也不剩。”可以得出規律,總的階梯數對每步跨的階梯數求餘的結果正好是剩餘階梯數。滿足題目的階梯數必須符合的條件是:

        (num%2==1&&num%3==2&&num%5==4&&num%6==5&&num%7==0)   假設階梯數為num。

源程式:

#include<stdio.h>
 
int main()
{
    int i;            //階梯數
    int count = 0;    //記錄滿足條件的階梯個數
    for (i = 1; i < 1000; i++)
    {
        if (i % 2 == 1 && i % 3 == 2 && i % 4 == 3&& i % 5 == 4 && i % 6 == 5 && i % 7 == 0)   //
題目條件         {             count++;             while (count == 1)             {                 printf("最少階梯數為:%d\n", i);      //輸出結果                 break;                                //如果有一個數滿足條件則跳出迴圈             }         }             }             return 0; }

最總求出結果為:119。


相關推薦

Keep Fighting All The Time

            著名的愛因斯坦階梯問題是這樣的:有一條長長長的階梯,,如果你每步跨2階,那麼最後剩1階;如果你每步跨3階,那麼最後剩2階;如果你每步跨5階,那麼最後剩4階;如果你每步跨6階,那麼最後剩5階;最有當你每步跨7階時,最後正好走完,一階也不剩。請問這條階梯

【Bluetata's Tech.Blog】We keep fighting all the way, not for changing the world, but for not being changed us by the world!

We keep fighting all the way, not for changing the world, but for not being changed us by the world!

HDOJ4355-Party All the Time(三分)

input arc cat ans 5.1 sea nim res stat Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go to

hdu 4355 Party All the Time(三分)

while pid const d+ ans acm space += bits 題目鏈接:hdu 4355 Party All the Time 題意: 有n個人,在一個一維的坐標軸上,現在讓他們聚在一起。 每個人移動一段距離會產生一個 不開心值=S3*W,現在問你最小的

I - Party All the Time (HDU - 4355)

while urn 所有 因此 ace gpo bsp name clu - 題目大意 有n個精靈在一維坐標軸上,並且每個精靈都有一個權值,每個精靈從一個點到達一個點要花費:S3*W(s代表距離),問所有的精靈要聚在一起,最小花費是多少。 - 解題思路 設最

The Upside to Being Screamed at, All the Time, for Everything

Early on in my design career, I had a job as a senior art director for the signature division of a Very Large Clothing Company. The title sounds terribly p

【liangge的專欄】You can fool all the people some of the time, and some of the people all the time, but you cannot fool all the peopl

You can fool all the people some of the time, and some of the people all the time, but you cannot fo...

從零開始 running all the time

1、server/service/engine/host/context} setting property 'source' to 'org.eclips....... 雙擊tomcat,修改伺服器配置,勾選Publish module contexts to separ

OATH FOR MYSELF(Updata all the time)

1 focus one thing at a time ,that's not only bring efficiency but also happiness. (i am just watching the teaching video,and thinking aho

C# signtool error:no certificates were found that met all the given criteria 錯誤解決方案

錯誤解決 證書 沒有 hat alt com img inf 時報 程序運行時報錯:signtool error:no certificates were found that met all the given criteria (漢譯:符號工具錯誤:沒有找到符合所有給定

CodeForces 622B The Time

題意:給你現在的時間,然後問你過了k分鐘後,是幾點了 #include<bits/stdc++.h> using namespace std; string s; int h,m,ss; int main() { cin>>s; for(int i=0

The issue about the GMT paper can't display all the seismograms

I try to display seismograms using 'pssac' by the command: gmt pssac *.z -JX20c/40c -R0/160/12/92 -Bx20+l'T(s)' -By2+lkm -BWSen -Ek -M1.5c -W0.5p,red &

HDU 4028 The time of a day (dp+離散化)

題意:給你1~n的數字,問你一個集合中的lcm大於m的集合有多少個 思路:這個題挺有意思的,我們直接的可以想到爆枚的話的複雜度有2^40,但是這些數中的lcm的答案缺不會有很多,最多也就是這40個數的lcm,所以不會有很大,那這樣的話我們用一個map來記錄dp[i]代表當前是有前i個數,對於每i個數的map

865. Smallest Subtree with all the Deepest Nodes(python+cpp)

題目: Given a binary tree rooted at root, the depth of each node is the shortest distance to the root. A node is deepest if it has the large

python合併矩陣報錯all the input arrays must have same....和vstack() takes 1 positional arrays....

python中使用numpy合併矩陣a,b 報錯 密集(dense)矩陣的合併不報錯,然而稀疏矩陣(sparse)報錯了,即在矩陣中,多數的元素為0。 ValueError: all the input arrays must have same number of

Latest Ripple News for All the Ripple Crypto Fans

Ripple has always been the most controversial virtual currency. You must have continuously heard about much good news and bad news about

Be a Man Keep fighting for destination

 舉個例子 UserModel,   一般來說 getModel(UserModel.class).save() 儲存表單,  客戶端前臺的 屬性 name 是 必須 以這種方式   name = "userModel.age " 才能儲存,假如不想全部加字首  getMo

How can I count the time it takes a function to complete in Java?

要知道 一個 function 需要執行多少個 ms, 用下面的程式就可以了,滿方便的。 long startTime = System.currentTimeMillis(); doReallyLongThing(); long endTime = System.currentTimeMil

Is it immoral to only spend 50% of the time at work productively?

I feel that people often make a big deal of somebody using 5 minutes of Facebook a day during the boss' time. I have the feeling that the average person on

A Smarter World: How AI, The IoT And 5G Will Make All The Difference

From fields and streams to offices, factories, hospitals and transportation systems, organizations are using internet of things (IoT) sensors to collect ma