日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

codeforces C. Vanya and Scales

發布時間:2025/3/8 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 codeforces C. Vanya and Scales 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
C. Vanya and Scales

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.

Input

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.

Output

Print word 'YES' if the item can be weighted and 'NO' if it cannot.

Sample test(s) input 3 7 output YES input 100 99 output YES input 100 50 output NO Note

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,現有w^0, w^1, w^2...w^100各一個重量的mass, 用其中的一些mass,時候能稱出m的重量。

也就是有如下圖的式子:

#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std;int main(){int m, w;cin>>w>>m;while(m){if(!((m-1)%w)) m--;else if(!((m+1)%w)) m++;else if(m%w){cout<<"NO"<<endl;return 0;}m/=w;}cout<<"YES"<<endl;return 0; }

?

轉載于:https://www.cnblogs.com/hujunzheng/p/4598396.html

總結

以上是生活随笔為你收集整理的codeforces C. Vanya and Scales的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。