📌  相关文章
📜  N的最小倍数,其二进制数表示形式中的N个数字正好

📅  最后修改于: 2021-04-27 22:35:53             🧑  作者: Mango

给定正整数N ,任务是在其二进制数表示形式中找到N个具有N个数字的最小倍数。
例子:

方法:想法是观察。

  • 如果我们仔细观察,一个序列将形成为1、2、6、8、20 …
  • 系列中的第N个术语是:
  • 因此,将数字N作为输入并实现以上公式。

下面是上述方法的实现:

C++
// C++ program to find smallest
// multiple of n with exactly N
// digits in Binary number System.
 
#include 
#include 
using namespace std;
 
// Function to find smallest multiple
// of n with exactly n digits
// in Binary number representation.
void smallestNumber(int N)
{
    cout << N * ceil(pow(2,
                         (N - 1))
                     / N);
}
 
// Driver code
int main()
{
    int N = 3;
    smallestNumber(N);
 
    return 0;
}


Java
// Java program to find smallest
// multiple of n with exactly N
// digits in Binary Number System.
class GFG{
 
// Function to find smallest
// multiple of n with exactly N
// digits in Binary Number System.
static void smallestNumber(int N)
{
    System.out.print(N * Math.ceil
                        (Math.pow(2, (N - 1)) / N));
}
 
// Driver code
public static void main(String[] args)
{
    int N = 3;
     
    smallestNumber(N);
}
}
 
// This code is contributed by shubham


Python3
# Python3 program to find smallest
# multiple of n with exactly N
# digits in Binary number System.
from math import ceil
 
# Function to find smallest multiple
# of n with exactly n digits
# in Binary number representation.
def smallestNumber(N):
    print(N * ceil(pow(2, (N - 1)) / N))
 
# Driver code
N = 3
smallestNumber(N)
 
# This code is contributed by Mohit Kumar


C#
// C# program to find smallest
// multiple of n with exactly N
// digits in Binary Number System.
using System;
 
class GFG{
 
// Function to find smallest
// multiple of n with exactly N
// digits in Binary Number System.
static void smallestNumber(int N)
{
    Console.Write(N * Math.Ceiling(
                      Math.Pow(2, (N - 1)) / N));
}
     
// Driver code
public static void Main(string[] args)
{
    int N = 3;
         
    smallestNumber(N);
}
}
 
// This code is contributed by AnkitRai01


Javascript


输出:
6