OCC '19 S2 - Rimuru's Number Game

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 64M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

It's Pookmeister's birthday, and Rimuru wants to give him a gift. Knowing that he loves the numbers 2 and 3, Rimuru wants to know how many different numbers less than or equal to N that only consist of digits that are either 2 or 3.


  1. (20 points) N \le 10^5
  2. (80 points) No additional constraints.

Input Specification

A single integer N (3 \le N \le 10^{18}).

Output Specification

The answer to the problem, on a single line.

Sample Input 1


Sample Output 1


Explanation for Sample 1

The only two numbers are 2 and 3.

Sample Input 2


Sample Output 2


Explanation for Sample 2

The only valid numbers are 2, 3, 22, 23, 32 and 33.


  • -4
    jaydenchu2003  commented on Feb. 11, 2020, 10:04 p.m.

    Anyone got a faster way for python?

    • 2
      CubixularHelix  commented on Sept. 26, 2020, 10:57 p.m.

      You don't need to check every number. Consider the implications of the numbers only having the digits 2 and 3.