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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

C. Vanya and Scales

發布時間:2023/11/29 编程问答 58 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C. Vanya and Scales 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard input output 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 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.

Examples 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.

?思路:如果是不只一個的話,那么就是轉換成k進制。

但是限制了一個,那么將這個數轉化為k進制,由于兩邊都能放,所以這個數可以看成是兩個數的差,并且這兩個數是由0,1組成的,那么就可以轉換成當前這個數加上一個只有0,1組成的數是否能組成另一個全0,1的數,要判斷的這個數的位上當前是0,1就不用加1,也就是

另一個數這位為0,否則如果等于n-1,就需要加1,否則無論加或不加1都不能得到當前位為0,或1,也就不能達到。

1 #include<stdio.h> 2 #include<algorithm> 3 #include<stdlib.h> 4 #include<queue> 5 #include<string.h> 6 #include<iostream> 7 #include<math.h> 8 #include<queue> 9 #include<vector> 10 using namespace std; 11 typedef long long LL; 12 const LL mod = 1e9+7; 13 int ak[100000]; 14 int main(void) 15 { 16 LL n,m; 17 while(scanf("%lld %lld",&n,&m)!=EOF) 18 { 19 int flag = 0; 20 int cn = 0; 21 while(m) 22 { 23 ak[cn++] = m%n; 24 m/=n; 25 } 26 int d = 0; 27 if(n==2)printf("YES\n"); 28 else 29 {for(int i = 0; i < cn; i++) 30 { 31 ak[i]+=d; 32 if(ak[i]==n-1) 33 { 34 ak[i]++; 35 } 36 d = ak[i]/n; 37 ak[i]=ak[i]%n; 38 if(ak[i]!=0&&ak[i]!=1) 39 flag = 1; 40 } 41 if(flag)printf("NO\n"); 42 else printf("YES\n");} 43 } 44 return 0; 45 }

代碼庫

轉載于:https://www.cnblogs.com/zzuli2sjy/p/5998664.html

總結

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

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