12400-3, 2, 1, 0 (mathematical thinking Questions & amp; high precision or table)

Source: Internet
Author: User

 

 

Ideas:

 

According to this idea, this sequence is actually unique, as shown in the following code: (1000 digits. For more information about the code, see the final part of the article)

3233232323222233222323222322322222332322232332333223232332222233232232233232223322232222233322223233323332333332323332333233333332233233222232223222222322322333322322222332323222322333232222222232223322332333223232233232222222323333323323232232333322333332223223322232323333232333332323233333323322223332223322222222232223332332332333233333233232333333233322223322222333333223232223232232223323232323333222323333332222333332222323323332323233332233323233233232332232223323223323222222323322333333323232322232222333233332232232233233332232223322233233232222222323333322322222222322323322333233333222323222222223222223233333223323232333223233222333232233333222233333322332322233332222333222323232223223233323223232332222332323232233333223333232232323322222233222333332223222233322323233233233232332323332222222332323322232332233323222222322333223322323322332232332222333222233333323332322232232232222233232332323332232222233323332233323223222232232232232332222333332332333333332223233333323323232223232

The O (1) Complexity code is as follows:

 

/*0.015s*/#include
 
  #include
  
   const int mx = 1000;const char s[mx + 1] = 233232323222233222323222322322222332322232332333223232332222233232232233232223322232222233322223233323332333332323332333233333332233233222232223222222322322333322322222332323222322333232222222232223322332333223232233232222222323333323323232232333322333332223223322232323333232333332323233333323322223332223322222222232223332332332333233333233232333333233322223322222333333223232223232232223323232323333222323333332222333332222323323332323233332233323233233232332232223323223323222222323322333333323232322232222333233332232232233233332232223322233233232222222323333322322222222322323322333233333222323222222223222223233333223323232333223233222333232233333222233333322332322233332222333222323232223223233323223232332222332323232233333223333232232323322222233222333332223222233322323233233233232332323332222222332323322232332233323222222322333223322323322332232332222333222233333323332322232232232222233232332323332232222233323332233323223222232232232232332222333332332333333332223233333323323232223232;int cnt[2][mx];int main(){for (int i = 1; i < mx; ++i){++cnt[s[mx - i - 1] - '2'][i];cnt[0][i] += cnt[0][i - 1];cnt[1][i] += cnt[1][i - 1];}int n, m, k;while (~scanf(%d%d%d, &n, &m, &k)){if (k && n >= cnt[1][k] && m >= cnt[0][k]) puts(s + mx - 1 - k);else puts(Impossible.);}return 0;}
  
 

Code for table creation: (enter 999 999 999)

 

 

/* 1.802 s */import java. io. bufferedInputStream; import java. math. bigInteger; import java. util. *; public class Main {static partition cin = new partition (new BufferedInputStream (System. in); public static void main (String [] args) {int N, M, K, kk, I; BigInteger MASK, ten, cur; char ans []; while (cin. hasNextInt () {N = cin. nextInt (); M = cin. nextInt (); K = cin. nextInt (); if (K = 0) {System. out. println (Impossible .); continue;} if (K> M + N) {System. out. println (Impossible .); continue;} MASK = BigInteger. valueOf (2 ). pow (K ). subtract (BigInteger. ONE); // MASK = 2 ^ k-1ans = new char [K]; kk = K; ten = BigInteger. ONE; cur = BigInteger. ZERO; for (I = 0; I <K; ++ I) {if (cur. and (BigInteger. ONE. shiftLeft (I )). equals (BigInteger. ZERO) {// The I-bit of the cur binary is 0ans [-- kk] = '2'; if (-- M <0) {System. out. println (Impossible .); break;} cur = cur. add (ten. multiply (BigInteger. valueOf (2); if (cur. compareTo (MASK)> 0) {cur = cur. and (MASK); // modulo to prevent the cur from slowing down the operation speed too much} else {// The I-bit of the cur binary is 1ans [-- kk] = '3 '; if (-- N <0) {System. out. println (Impossible .); break;} cur = cur. add (ten. multiply (BigInteger. valueOf (3); if (cur. compareTo (MASK)> 0) {cur = cur. and (MASK); // modulo to prevent the cur from slowing down the computation speed.} ten = ten. multiply (BigInteger. valueOf (10);} if (I = K) System. out. println (ans );}}}


 

Related Article

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.