1 second
256 megabytes
standard input
standard 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 massm 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.
The 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.
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
3 7
YES
100 99
YES
100 50
NO
Note 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.
开始是没有读懂题,好奇怪,为什么老是这样子,后来才看明白,题意大概是这样子的:
现在有一个重量为m的物品 放到天平上 利用一些砝码使得天平平衡砝码的重量为w的i次方 问有没有一种方式使得天平平衡 。
然后是做法,额,是个多项式的问题,每个砝码只有三种选择 不放 放左边 放右边
其实就是等式a0*w^0+a1*w^1+……+an*w^n=m有没有解的情况 ai的值只能是0 1 -1
对于这个等式 让m不断的除以w 则模m得到的值只能是 0 1 w-1(-1)
#include<string.h>
#include<stdio.h>
#define LL __int64
LL w,m;
int main()
{
scanf("%I64d%I64d",&w,&m);
if(w<=)
{
printf("YES\n");
return ;
}
while(m)
{
if(!((m-)%w)) m--;
else if(!((m+)%w)) m++;
else if(m%w) {printf("NO\n");return ;}
m=m/w;
}
printf("YES\n");
return ;
}
Codeforces Round #308 (Div. 2)----C. Vanya and Scales的更多相关文章
-
暴力/进制转换 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 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 ...
-
水题 Codeforces Round #308 (Div. 2) A. Vanya and Table
题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...
-
数学 Codeforces Round #308 (Div. 2) B. Vanya and Books
题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...
-
Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题
D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...
-
Codeforces Round #308 (Div. 2)B. Vanya and Books 数学
B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...
-
Codeforces Round #308 (Div. 2) A. Vanya and Table 暴力
A. Vanya and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...
-
Codeforces Round #308 (Div. 2)
A. Vanya and Table Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows ...
-
Codeforces Round #308 (Div. 2) A B C 水 数学
A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
-
CSS3属性box-sizing
1.box-sizing属性是CSS3的属性,有3个值:border-box.content-box.inherit. 2.默认是content-box,就是我们知道的width.padding.bo ...
-
https://zeroc.com/index.html
https://zeroc.com/index.html http://blog.shutupandcode.net/?p=1085
-
jsdoc文档
官网文档:http://usejsdoc.org/index.html一个比较全的jsdoc示例 /** * @fileoverview 文件上传队列列表显示和处理 * @author 水车 **/ ...
-
R语言成功加载rJava方法
加载rJava的同时,要下载JAVA的JRE并且配置环境变量JAVA_HOME,因为rJava的调用需要java运行环境. 1.下载JRE 64位版本的JRE官网下载:http://www.java. ...
-
nodejs安装及故障解决
本文来自:http://hxl2009.blog.51cto.com/779549/1031320 给开发搞nodejs环境,遇到点问题记录下过程,备忘. wget http://nodejs.org ...
-
Python学习之路基础篇--08Python基础+ 文件的基本操作和 注册小作业
1 文件的基本操作 #1. 打开文件的模式有(默认为文本模式): r ,只读模式[默认模式,文件必须存在,不存在则抛出异常] w,只写模式[不可读:不存在则创建:存在则清空内容] a, 只追加写模式[ ...
-
NewZealand。。。
秀个存在感...
-
day11 内置函数
特殊算数运算 计算整数的和 l = [1,2,3,4,5] print(sum(l)) 除法运算,然后取余 在做页面的时候可以根据数据量分页的时候使用 print(divmod(10,3)) # (3 ...
-
DevExpress WinForms使用教程:Diagram Control
[DevExpress WinForms v18.2下载] DevExpress WinForms v18.2包含WinForms和WPF Diagram Controls的三个高要求功能:新的Dia ...
-
js文字展示各种滚动效果
js文字展示各种滚动效果:http://www.dowebok.com/demo/188/