CF-gym-100523-C(水題)

來源:互聯網
上載者:User

標籤:

Will It Stop?

Available memory: 64 MB.

   Byteasar was wandering around the library of the University of Warsaw and at one of its facades he noticed a piece of a program with an inscription “Will it stop?”. The question seemed interesting, so Byteasar tried to tackle it after returning home. Unfortunately, when he was writing down the piece of code he made a mistake and noted:

     while n > 1 do

       if n mod 2 = 0 then

        n := n=2

       else

        n := 3 · n + 3

   Byteasar is now trying to figure out, for which initial values of the variable n the program he wrote down stops. We assume that the variable n has an unbounded size, i.e., it may attain arbitrarily large values.

Input

The first and only line of input contains one integer n (2<=n<=10^14).

Output

In the first and only line of output you should write a single word TAK (i.e., yes in Polish), if the program stops for the given value of n, or NIE (no in Polish) otherwise.

Example

For the input data: 4

the correct result is: TAK

 

分析:根據題目給的迴圈,在裡面加一句,如果當前的n已經出現過,接下來又是重複了,則會一直死迴圈,就直接退出。

 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <ctime> 5 #include <iostream> 6 #include <algorithm> 7 #include <set> 8 #include <vector> 9 #include <sstream>10 #include <queue>11 #include <typeinfo>12 #include <fstream>13 #include <map>14 #include <stack>15 using namespace std;16 #define INF 10000017 typedef unsigned long long ul;18 const int maxn=10010;19 map<ul,int> mp;20 int main()21 {22     ul n;23     scanf("%I64u",&n);24     int flag=1;25     while(n>1){26         mp[n]=1;27         if(n%2==0) n=n/2;28         else n=3*n+3;29         if(mp[n]==1) {flag=0;break;}30     }31     if(flag==1) printf("TAK\n");32     else printf("NIE\n");33     return 0;34 }

 

CF-gym-100523-C(水題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.