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转化成 ...
随机推荐
- 应用程序中的server错误,没有名称为“ServiceBehavior”的服务行为
应用程序中的server错误,没有名称为"ServiceBehavior"的服务行为 今天在阅读"创建和使用Web服务"的相关内容,在浏览器中查 ...
- LSA、LDA
Latent semantic analysis (LSA) is a technique in natural language processing, in particular distrib ...
- Angularjs: call other scope which in iframe
Angularjs: call other scope which in iframe -------------------------------------------------------- ...
- C#获取电脑的相关信息
/* 创建者:菜刀居士的博客 * 创建日期: 2014年08月31号 * 功能:获取电脑的相关信息 * */ namespace Net.String.ConsoleApplication { ...
- nginx 配置nginx.conf,负载均衡,逻辑分流
nginx 最重要的配置文件nginx.conf: 一般的配置我不做解释,网上到处都是,主要对主要的几点进行注释(如下) worker_processes ; error_log /data/logs ...
- Pascal Hexagrammum Mysticum 的深度探索
PASCAL . Hexagrammum Mysticum . (六角迷魂图) . 的深度探索 . 英中对比.英文蓝色,译文黑色,译者补充说明用紫红色 (已校完,但尚未定稿,想再整理并补充内容 ...
- 通过/proc/cpuinfo判断CPU数量、Multicores、Multithreading、Hyper-threading
http://blog.sina.com.cn/s/blog_4a6151550100iowl.html 判断依据:1.具有相同core id的cpu是同一个core的超线程.2.具有相同physic ...
- TCP连接建立与终止,及状态转换
TCP连接建立 三路握手 三路握手发生在客户端发起connect请求到服务端accept返回中,在三路握手发生前,服务端必须准备好接受外来连接,这通常通过服务端调用 (socket.bind.list ...
- Java Management Extensions (JMX) Flume
Lesson: Overview of the JMX Technology (The Java™ Tutorials > Java Management Extensions (JMX)) h ...
- Hadoop_stack_cmd
HDFS命令基本格式:Hadoop fs -cmd < args > HDFS命令基本格式:Hadoop fs -cmd < args > ls 命令 hadoop fs -l ...