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已经出现过,接下来又是重复了,则会一直死循环,就直接退出。

 #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>
using namespace std;
#define INF 100000
typedef unsigned long long ul;
const int maxn=;
map<ul,int> mp;
int main()
{
ul n;
scanf("%I64u",&n);
int flag=;
while(n>){
mp[n]=;
if(n%==) n=n/;
else n=*n+;
if(mp[n]==) {flag=;break;}
}
if(flag==) printf("TAK\n");
else printf("NIE\n");
return ;
}

CF-gym-100523-C(水题)的更多相关文章

  1. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  2. CF 628A --- Tennis Tournament --- 水题

    CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...

  3. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  4. UVaLive 6591 && Gym 100299L Bus (水题)

    题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...

  5. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  6. CodeForces Gym 100685C Cinderella (水题)

    题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...

  7. Two Operations Gym - 102263M 优先队列水题

    Two Operations Gym - 102263M Ayoub has a string SS consists of only lower case Latin letters, and he ...

  8. Gym 100531G Grave(水题)

    题意:给定一个大矩形,再给定在一个小矩形,然后给定一个新矩形的长和高,问你能不能把这个新矩形放到大矩形里,并且不与小矩形相交. 析:直接判定小矩形的上下左右四个方向,能不能即可. 代码如下: #pra ...

  9. 一道cf水题再加两道紫薯题的感悟

    . 遇到一个很大的数除以另一个数时,可以尝试把这个很大的数进行,素数因子分解. . 遇到多个数的乘积与另一个数的除法时,求是否能整除,可以先求每一个数与分母的最大公约数,最后若分母数字为1,则证明可整 ...

  10. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

随机推荐

  1. Linux下搭建BT服务器

    P2P(Peer to Peer 即对等网络)就是在这种背景下提出的一种网络技术,P2P可以简单地定义为通过直接交换信息,共享计算机资源和服务,对等计算机兼有客户机和服务器的功能.在这种网络中所有的节 ...

  2. [Irving]Sql Server 日期、时间、比较

    在sql 的数据库表里时间字段是比较全的格式:例如GetdataTime字段:2007-06-05 12:34:50. 但在前台程序里,利用日历控件,可能查询的时候是以某天来做比较,例如开始时间:20 ...

  3. Problem - 433C - Codeforces解题报告

    对于这题本人刚开始的时候的想法是:先把最大两数差的位置找到然后merge计算一个值再与一连串相同的数做merge后计算一个值比较取最大值输出:可提交后发现不对,于是本人就搜了一下正解发现原来这题的正确 ...

  4. HW2.18

    public class Solution { public static void main(String[] args) { System.out.println("a" + ...

  5. 组件局域网中的无集线器、Windows XP、Windows 7、Windows 8的对等网

     为什么要用对等网? 答:对等网采用分散管理的方式,网络中的每台计算机既作为客户机又可作为服务器来工作,每个用户都管理自己机器上的资源. 组建局域网中无集线器的对等网 组建局域网中Windows XP ...

  6. A Tour of Go Structs

    A struct is a collection of fields. (And a type declaration does what you'd expect.) package main im ...

  7. sql server smo

    在SQL Server2005以前的版本中,SQL分布式管理对象(SQL-DMO)为我们提供了非常有效的方法来通过编程的方式管理SQL Server.SQL-DMO支持基于COM的接口,开发人员可以通 ...

  8. HDU 2554 N对数的排列问题

    LINK:HDU 2554 这是昨天晚上小练里面比较有趣的一道题~我在做的时候思路错了,以为数字的排列会有规律,结果后面发现就算有也很难找......╮(╯▽╰)╭ 看了网上的题解,有一种恍然大悟的感 ...

  9. 通过Response.Flush()实现IE下载失败的问题

    通过Response.Flush()实现对服务端文件的下载时,会失败,不能正常弹出IE下载框,经过测试发现需要进行如下设置后即可解决. 进入 [工具]--->[Internet选项]---> ...

  10. java多态/重载方法——一个疑难代码引发的讨论

    直接上代码,看这个代码发现自己的基础有多差了.参考 http://www.cnblogs.com/lyp3314/archive/2013/01/26/2877205.html和http://hxra ...