codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1567C.md (2414B)


      1 Source: https://codeforces.com/problemset/problem/1567/C
      2 
      3 C. Carrying Conundrum
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Alice has just learned addition. However, she hasn't learned the concept of "carrying" fully — instead of carrying to the next column, she carries to the column two columns to the left.
     22 
     23 For example, the regular way to evaluate the sum $2039 + 2976$ would be as shown:
     24 
     25  ![](https://espresso.codeforces.com/a1205eb01f76276aa971fb9a8586bef07b46ad2d.png) 
     26 
     27 However, Alice evaluates it as shown:
     28 
     29  ![](https://espresso.codeforces.com/b8fb0425bb54e334f87a37a00daa5e40649620ba.png) 
     30 
     31 In particular, this is what she does:
     32 
     33 * add $9$ and $6$ to make $15$, and carry the $1$ to the column two columns to the left, i. e. to the column "$0$ $9$";
     34 * add $3$ and $7$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column "$2$ $2$";
     35 * add $1$, $0$, and $9$ to make $10$ and carry the $1$ to the column two columns to the left, i. e. to the column above the plus sign;
     36 * add $1$, $2$ and $2$ to make $5$;
     37 * add $1$ to make $1$.
     38 
     39 Thus, she ends up with the incorrect result of $15005$.
     40 
     41 Alice comes up to Bob and says that she has added two numbers to get a result of $n$. However, Bob knows that Alice adds in her own way. Help Bob find the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$. Note that pairs $(a, b)$ and $(b, a)$ are considered different if $a \ne b$.
     42 
     43 Input
     44 
     45 The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. The description of the test cases follows.
     46 
     47 The only line of each test case contains an integer $n$ ($2 \leq n \leq 10^9$) — the number Alice shows Bob.
     48 
     49 Output
     50 
     51 For each test case, output one integer — the number of ordered pairs of positive integers such that when Alice adds them, she will get a result of $n$.
     52 
     53 Example
     54 
     55 Input
     56 
     57 ```
     58 5
     59 100
     60 12
     61 8
     62 2021
     63 10000
     64 ```
     65 
     66 Output
     67 
     68 ```
     69 9
     70 4
     71 7
     72 44
     73 99
     74 ```
     75 
     76 Note
     77 
     78 In the first test case, when Alice evaluates any of the sums $1 + 9$, $2 + 8$, $3 + 7$, $4 + 6$, $5 + 5$, $6 + 4$, $7 + 3$, $8 + 2$, or $9 + 1$, she will get a result of $100$. The picture below shows how Alice evaluates $6 + 4$:
     79 
     80  ![](https://espresso.codeforces.com/3a74ab310accd36e8ca570f5a5479d7035c2e6b3.png)