Uvaoj 550-multiplying by rotation

Source: Internet
Author: User

Question

Question omitted.

Analysis: I expanded the formula, pushed something out, enumerated digits, and then obtained an X, if X represents the number under the base where the current total number of digits minus one, the current number of digits is the minimum. After the write, TLE determines that it may take a long time.

After reading other people's questions, I found my consideration complicated. In fact, this is a multiplication operation of multiplying Multiple Digits by one digit in base bitwise. The vertical format is as follows,

A0a1a2... an-1c

× F

----------------------

Ca0a1a2... an-1

(A0a1a2... the an-1c represents factor1, f Represents factor2, and C represents the number to be moved ).

For example, after C * F is a bitwise operation, the result C * F is represented as C * F/base and (C * f) % base at base, where C * f/base is the carry, and C * F % base is the current bit of the result. It is determined by the question conditions, and an-1 = C * F % base.

So we continue with an-1 * F until the current bit of the result is equal to C and the carry value is 0. It can be seen that this is the type of question given by elementary school students to leave a few blank spaces, but it is changed from decimal to base.

Code:

 
# Include <iostream> # include <cmath> # include <string> using namespace STD; int main () {int base, n, m; while (CIN> base> N> m) {If (M = 1) {cout <1 <Endl; continue;} int carry = 0, cur = N, I = 1; for (; I ++) {int TMP = cur * m + carry; carry = tmp/base; // enter the full base into the cur = TMP % base; // current bit if (carry = 0 & cur = N) {cout <I <Endl; break; }}return 0 ;}

Tle code:

# Include <iostream> using namespace STD; int B, C, F; Int Is (INT X, int N) // can X be represented as the N-digit number in B {int CNT = 0; For (; X/= B, CNT ++); If (CNT = N) return 1; else return 0;} int main () {While (CIN> B> C> F) {int I; // number of digits of the first factor n int B _pow = 1; // n-1 times of B for (I = 1; B _pow <= f; I ++) B _pow * = B; // ① can n be 1? ② <=, X cannot be 0? For (; I ++, B _pow * = B) {int T1 = C * (B _pow-f); int t2 = (F * b-1); If (T1% T2! = 0) continue; // X is an integer int x = t1/T2; If (is (x, I-1) {cout <I <Endl; break ;}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.