hdu 4952 Number Transformation (找規律)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   io   for   ar   

題目連結

題意:給你個x,k次操作,對於第i次操作是:要找個nx,使得nx是>=x的最小值,且能整除i,求k次操作後的數

分析:

經過打表找規律,會發現最後的x/i,這個倍數會趨於一個固定的值,求出這個固定的值和K相乘就可以了,

為什麼會趨於固定的值呢,因為最後雖然i在不斷增長,但是x也是在增長的,每次的倍數會回退一個發現

有餘數,然後再加上一個,所以趨於穩定。

 

官方題解:

 

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 #define LL __int64 7 using namespace std; 8  9 int main()10 {11     LL x, k, i, pre, tmp;12     int ca = 1;13     while(~scanf("%I64d%I64d", &x, &k))14     {15         if(x==0 && k==0) break;16         pre = x/1;17         for(i = 2; i <= k; i++)18         {19             tmp = x/i;20             if(x%i==0)21             {22                 pre = tmp;23                 continue;24             }25             x = (tmp+1)*i;26             if(pre == tmp+1) // 和之前的相同27                 break;28             pre = tmp+1;29         }30 31         printf("Case #%d: ", ca++);32         printf("%I64d\n", pre*k);33     }34     return 0;35 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.