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转化成 ...
随机推荐
- java zip 工具类
原文:http://www.open-open.com/code/view/1430906539866 package com.topsoft.websites.utils; import java. ...
- Effective C++ 条款九、十 绝不在构造和析构过程中调用virtual函数|令operator=返回一个reference to *this
1.当在一个子类当中调用构造函数,其父类构造函数肯定先被调用.如果此时父类构造函数中有一个virtual函数,子类当中也有,肯定执行父类当中的virtual函数,而此时子类当中的成员变量并未被初始 ...
- PHP将当前目录列出来
$d=dir("."); echo $d->path; while(false !== ($e = $d->read())) { echo "<a hr ...
- 芯片史称:“长平之战”----Intel的东进与ARM的西征(3)--人生如戏,全靠演技
http://www.36kr.com/p/177143.html 从 2003 年到 2008 年,处理器双雄 Intel 和 AMD 在 64 位 CPU 领域展开了一场长达五年,极为惨烈的科技战 ...
- webservice client setTimeOut
一:eclipse生成的client,基于axis client_sub.getOptions().setTimeOutInMilliSeconds(1000*60); client_sub表示一个客 ...
- SpringMVC+ajaxFileUpload上传图片 IE浏览器弹下载框问题解决方式
如题,简单记录一下这个问题的解决的方法,导致问题的核心原因是:ajaxfileupload不支持响应头ContentType为application/json的设置.而且IE也不支持这样的格式,而当我 ...
- hdu 1757 A Simple Math Problem (矩阵高速幂)
和这一题构造的矩阵的方法同样. 须要注意的是.题目中a0~a9 与矩阵相乘的顺序. #include <iostream> #include <cstdio> #include ...
- 解决ubuntu10.04不能上网
1:命令行输入:lspci查看驱动,最后几行如果有ethernet controller:atheros communications ar8151 v1.0*的话,就说明驱动没有安装好, 2:下载地 ...
- Java 8 新的时间日期 API
1. 概述 1.1 简介 Java 8 引入了一套全新的时间日期API,操作起来更简便.简单介绍下,LocalDate和LocalTime和LocalDateTime的使用: java.util.Da ...
- YTU 2481: 01字串
2481: 01字串 时间限制: 1 Sec 内存限制: 128 MB 提交: 103 解决: 72 题目描述 对于长度为7位的一个01串,每一位都可能是0或1,一共有128种可能.它们的前几个是 ...