1. Title Description: Click to open the link
2. Problem-solving ideas: The subject can be carried out in advance a simple mathematical deduction solution. The actual equation to be satisfied is the following formula:
A0*w^0+a1*w^1+a2*w^2+...+an*w^n=m
In the equation, all AI should be one of the numbers in {0,1,-1}, so that after deduction, the approximate solution is surfaced. is to constantly take the W modulus, and then m/=w, see whether the remainder satisfies the conditions can be. But here also to think more deeply, first of all it is not difficult to find, if w≤3, then must meet test instructions; When w>3, because the modulo operation will not have the remainder of-1, it can be w-1, so then M divided by the W to add 1, said to subtract one more time W, so w-1 changed to-1, As long as the surplus is found to be unsatisfied, the output is no.
3. Code:
#define _crt_secure_no_warnings#include<iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;typedef long Long ll;typedef unsigned Long long ull; #define ME (s) memset (s,0,sizeof (s)) #define for (i,n) for (int i=0;i< (n); i++) #define PB Push_back#define SZ size#define CLR Clear#define F (A, b) for (int i=a;b;i++) int main () {int x, y;while (cin >> x >> y) { if (x <= 3)//At this time must meet test instructions {printf ("yes\n"); Goto X1; } while (Y > 0) {int z = y% x; if (z <= 1)//The remainder is 0,1 y/= x; else if (z = = x-1)//equivalent to the remainder is -1 y = y/x + 1;//divided by x to add 1 else//remainder does not satisfy the condition,Direct output NO {printf ("no\n"); Goto X1; }} printf ("yes\n"); X1:; }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
#308 (Div.2) c. Vanya and Scales