1680. Concatenation of Consecutive Binary Numbers Medium

@problem@discussion
#Math#Bit Manipulation#Simulation



1/**
2 * [1680] Concatenation of Consecutive Binary Numbers
3 *
4 * Given an integer n, return the decimal value of the binary string formed by concatenating the binary representations of 1 to n in order, modulo 10^9 + 7.
5 *  
6 * Example 1:
7 * 
8 * Input: n = 1
9 * Output: 1
10 * Explanation: "1" in binary corresponds to the decimal value 1. 
11 * 
12 * Example 2:
13 * 
14 * Input: n = 3
15 * Output: 27
16 * Explanation: In binary, 1, 2, and 3 corresponds to "1", "10", and "11".
17 * After concatenating them, we have "11011", which corresponds to the decimal value 27.
18 * 
19 * Example 3:
20 * 
21 * Input: n = 12
22 * Output: 505379714
23 * Explanation: The concatenation results in "1101110010111011110001001101010111100".
24 * The decimal value of that is 118505380540.
25 * After modulo 10^9 + 7, the result is 505379714.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	1 <= n <= 10^5
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/
36// discuss: https://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn concatenated_binary(n: i32) -> i32 {
42        0
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_1680() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.