1261. Tips

Time limit: 1.0 second
Memory limit: 64 MB
The favorite resting place of the Ural programmers is Threenland island. There is only one tribulation: dollars and euro don’t go about here. So the tourists are to exchange their money into threets (the currency of Threenland). There go about 1 threet, 3 threets, 9 threets, 27 threets, …, 3k threets, … Once programmer Vasechkin, after the N-threets bill was given to him found out, that he’d got one paper of each denomination. Waiters in Threenland have a custom to keep the change. Waiters like to get the tip that can be presented by a set of papers in which paper of each denomination appears not more than once. Otherwise their feelings are hurt. They have a peeve on a client if they don’t get tips at all. Help please Vasechkin to pay for the dinner and not to hurt the waiter.

Input

consists of an integer N. 1 ≤ N ≤ 107.

Output

Output two integers separated with a space – that is the sum that Vasechkin is to pay and an amount of tips. If there are several solutions choose any of them. If there is no solution output 0. Remember that Ural programmers are not rich, so Vasechkin can’t pay more than 4294967291 threets.

Sample

input output
5
9 4

题意:给出一个数n,要求求出两个数a,b;a和b的3进制表示没有2;并且b+n=a;并且按a b的格式输出;

思路:利用进制运算的思想,将给出的数n变成3进制表示,然后再2出现的位置加1,直到没有了2为止,并且在加的过程中记录加数;最后这个加数便是b;

 #include <iostream>
using namespace std;
int tip=,bill=,n,m=;
int main()
{
cin >> n;
bill=n;
do
{
if (n%==)
{
tip+=m;
++n;
}
n/=,m*=;
}while (n);
if (!tip) tip=m;
cout <<bill+tip<< ' ' << tip << endl;
return ;
}

ural 1261. Tips(进制运算)的更多相关文章

  1. shell算术运算与进制运算

    (())与let是等效的 arithmetic expression type 与[是等效的 source与.是等效的 其实,Shell(这里是Bash)本身不具备处理浮点计算的能力,但是可以使用“b ...

  2. Python全栈之路----进制运算

    1.进制拾遗 二进制:01 八进制:01234567 十进制:0123456789 十六进制:0123456789ABCDEF  (a是10,b是11,c是12,d是13,e是14,f是15) 2.进 ...

  3. 洛谷 P1013 进制位 【搜索 + 进制运算】

    题目描述 著名科学家卢斯为了检查学生对进位制的理解,他给出了如下的一张加法表,表中的字母代表数字. 例如: + L K V E L L K V E K K V E KL V V E KL KK E E ...

  4. JAVA基础学习之命令行方式、配置环境变量、进制的基本转换、排序法、JAVA文档生成等(1)

    1.命令行方式 dos命令行,常见的命令: dir:列出当前目录下的文件以及文件夹 md:创建目录 rd:删除目录 cd:进入指定目录 cd..:退回到上一级目录 cd/:退回到根目录 del:删除文 ...

  5. ACM 16进制的简单运算

    16进制的简单运算 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果.   输入 第一行输入一个正整 ...

  6. NYOJ--244--16进制的简单运算(C++控制输入输出)

    16进制的简单运算 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 现在给你一个16进制的加减法的表达式,要求用8进制输出表达式的结果.   输入 第一行输入一个正整 ...

  7. JAVA之旅(一)——基本常识,JAVA概念,开发工具,关键字/标识符,变量/常量,进制/进制转换,运算符,三元运算

    JAVA之旅(一)--基本常识,JAVA概念,开发工具,关键字/标识符,变量/常量,进制/进制转换,运算符,三元运算 Android老鸟重新学一遍JAVA是什么感觉?枯燥啊,乏味啊,而且归纳写博客,都 ...

  8. C# 2进制、8进制、10进制、16进制...各种进制间的转换(三) 数值运算和位运算

    一.数值运算 各进制的数值计算很简单,把各进制数转换成 十进制数进行计算,然后再转换成原类型即可. 举例 :二进制之间的加法 /// <summary> /// 二进制之间的加法 /// ...

  9. import导入模块,==和is,浅拷贝和深拷贝,进制转换,位运算,私有化,property装饰器

    '''import导入模块'''import sysprint(sys.path) sys.path.append('D://ASoft/Python/PycharmProjects')import ...

随机推荐

  1. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  2. Masonry 添加约束要注意顺序

    对一个视图添加约束,其依赖的约束必须先已经存在,不能依赖该代码后的约束,否则造成不可预料的结果,如下代码能达到预期效果 - (void)makeConstraints { __weak typeof( ...

  3. 正确的IP地址正则表达式

    ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)

  4. springmvc+maven

    http://blog.csdn.net/zht666/article/details/8673609/

  5. VM10下Ubuntu无法安装vim的问题

    今天在VM10下重装了Ubuntu14.10,安装vim时发现如下问题 谷歌了一下,终于找到一种方法解决. 终端下: sudo vi /etc/apt/source.list 该命令将用vi打开一个文 ...

  6. 1.1 office安装

    2013版安装链接: https://pan.baidu.com/s/1qYMuidA 密码: uj9e

  7. Asp.Net MVC2.0 Url 路由入门---实例篇

    本篇主要讲述Routing组件的作用,以及举几个实例来学习Asp.Net MVC2.0 Url路由技术. 接着上一篇开始讲,我们在Global.asax中注册一条路由后,我们的请求是怎么转到相应的Vi ...

  8. Python编程工具IDLE快捷键

    IDLE编辑器快捷键 自动补全代码        Alt+/(查找编辑器内已经写过的代码来补全) 补全提示              Ctrl+Shift+space(默认与输入法冲突,修改之) (方 ...

  9. was性能调优前期准备

    http://www.ibm.com/developerworks/cn/websphere/library/techarticles/0707_wudan/#resources was应用服务器环境 ...

  10. log4j.properties全配置 (转)

    ###############################log4j.properties############################### ##### Global Log Leve ...