Codeforces Gym 100523C C

C - Will It Stop?
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87794#problem/C

Description

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 ¬ 1014).

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.

Sample Input

4

Sample Output

TAK

HINT

题意

给你一个数,然后问你这个数组是否会无限循环

题解

暴力10000000次,然后看看就吼了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 5000
#define mod 10007
#define eps 1e-9
int Num;
//const int inf=0x7fffffff;   //нчоч╢С
const int inf=0x3f3f3f3f;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************

int main()
{
    unsigned long long n;
    cin>>n;
    int tot=0;
    while(n>1)
    {
        if(n%2==0)
            n=n/2;
        else
            n=3*n+3;
        tot++;
        if(tot>10000000)
        {
            cout<<"NIE"<<endl;
            return 0;
        }
    }
    cout<<"TAK"<<endl;
    
}
原文地址:https://www.cnblogs.com/qscqesze/p/4731115.html