📜  可被 X 整除的最大 K 位数的Python程序

📅  最后修改于: 2022-05-13 01:56:56.581000             🧑  作者: Mango

可被 X 整除的最大 K 位数的Python程序

给出了整数 X 和 K。任务是找到可被 X 整除的最大 K 位数。

例子:

Input : X = 30, K = 3
Output : 990
990 is the largest three digit 
number divisible by 30.

Input : X = 7, K = 2
Output : 98

一个有效的解决方案是使用以下公式。

ans = MAX - (MAX % X)
where MAX is the largest K digit 
number which is  999...K-times

该公式适用于简单的学校方法划分。我们删除余数以获得最大的可除数。

# Python code to find highest 
# K-digit number divisible by X
  
def answer(X, K):
      
    # Computing MAX
    MAX = pow(10, K) - 1
      
    #returning ans
    return (MAX - (MAX % X))
  
X = 30; 
K = 3; 
  
print(answer(X, K)); 
  
# Code contributes by Mohit Gupta_OMG <(0_o)>

输出 :

990

请参阅完整文章关于可被 X 整除的最大 K 位数字以获取更多详细信息!