C. Vanya and Scales
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams where w is some integer not less than 2(exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
InputThe first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109) — the number defining the masses of the weights and the mass of the item.
OutputPrint word 'YES' if the item can be weighted and 'NO' if it cannot.
Examplesinput3 7outputYESinput100 99outputYESinput100 50outputNONoteNote to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
#include<bits/stdc++.h>
using namespace std; int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
while(b)
{
c=b%a;
if(!c)b/=a;
else if(c==){b=(b-)/a;}
else if(c==a-){b=(b+)/a;}
else{puts("NO");return ;}
}
puts("YES");
}
C. Vanya and Scales的更多相关文章
- codeforces C. Vanya and Scales
C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...
- CodeForces 552C Vanya and Scales
Vanya and Scales Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u S ...
- Codeforces Round #308 (Div. 2)----C. Vanya and Scales
C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs
C. Vanya and Scales Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/p ...
- Vanya and Scales(思维)
Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales
题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...
- codeforces 552 C Vanya and Scales
这个题的意思就是给出一个数m.以及一个以1为首元素.w为比例常数的等比数列,数列长度为101,数列中每一个数字最多仅仅能用一次.问是否存在xa+wb+--=wc+wd+--+we+m. 非常显然,换句 ...
- 【30.23%】【codeforces 552C】Vanya and Scales
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 552C Vanya and Scales(思路)
题目大概说有101个质量w0.w1.w2.....w100的砝码,和一个质量m的物品,问能否在天平两边放物品和砝码使其平衡. 哎,怎么没想到..注意到w0.w1.w2.....w100—— 把m转化成 ...
随机推荐
- [转] Python 常用第三方模块 及PIL介绍
原文地址 除了内建的模块外,Python还有大量的第三方模块. 基本上,所有的第三方模块都会在PyPI - the Python Package Index上注册,只要找到对应的模块名字,即可用pip ...
- WIP - 离散任务点击组件-错误:LOCATOR.CONTROL 的变元无效:ORG_LOCATOR_CONTROL=''
Getting Error "Invalid Argument to LOCATOR.CONTROL: ORG_LOCATOR_CONTROL='' in Material Requirem ...
- IOS开发 二维码功能的实现
原帖地址:http://yul100887.blog.163.com/blog/static/20033613520121020611299/ 如今二维码随处可见,无论是实物商品还是各种礼券都少不了二 ...
- OD调试器调试Delphi程序按钮事件断点方法
这几天我调试一个Delphi程序,总是无法断点按钮事件,像我这样的菜鸟断点按钮事件真心累啊.所以我分享一下我下断点的经验!希望新手们少走弯路!! 工具/原料 OD调试器 Delphi程序 方法 ...
- TraceTool 跟踪工具的瑞士军刀(C++版使用)
TraceTool查看器能够显示多种类型的来源(从提供的框架.日志文件.事件日志.或者OutputDebugString方法).一个简单而强大的client框架发送简单的跟踪,分组跟踪.类和对象浏览器 ...
- java中等待所有线程都执行结束(转)
转自:http://blog.csdn.net/liweisnake/article/details/12966761 今天看到一篇文章,是关于java中如何等待所有线程都执行结束,文章总结得很好,原 ...
- android studio——Could not find method externalNativeBuild()
gradle同步工程时出现错误 Error:(36, 0) Could not find method externalNativeBuild() for arguments [build_cazi7 ...
- SQL server创建和管理
数据库函数的应用 数据库的查询方法 修改和替换数据库的数据
- Java字符串String 集合的迭代器
Java字符串String 我们知道Java的字符窜是Immutable(不可变)的,一旦创建就不能更改其内容了:平常我们对字符串的操作是最多的,其实对字符串的操作,返回的字符串都是新建的字符串对象, ...
- 网络请求--Retrofit2用法
欢迎Follow我的GitHub, 关注我的CSDN. Retrofit是Square开发的网络请求库, 简化了网络请求的使用, 这个库太知名了, 优点我就不多说了. 让我们看看怎样使用吧? 注意: ...