给定一个数字,任务是检查数字是否可以被20整除。输入数字可能很大,可能无法存储long long int,并且它可能非常大,所以我们使用字符串。
例子:
Input : 7575680
Output : Yes
Input : 987985865687690
Output : No
如果数字可以被5和4整除,则数字可以被20整除。我们可以通过检查最后两位数是否可以被4整除来检查数字是否可以被4整除。可以通过检查最后一位数字来将数字整除为5。同样,如果数字的最后一位数字为零,而第二位最后一位数字为2的倍数,则该数字可被20整除。
C++
// CPP program to check if a large number
// is divisible by 20.
#include
using namespace std;
bool divisibleBy20(string num)
{
// Get number with last two digits
int lastTwoDigits = stoi(num.substr(num.length() - 2,
num.length() - 1));
// Check if the number formed by last two
// digits is divisible by 5 and 4.
return ((lastTwoDigits % 5 == 0) &&
(lastTwoDigits % 4 == 0));
}
int main()
{
string num = "63284689320";
if (divisibleBy20(num))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
Java
// Java program to check if a large n
// number is divisible by 20.
import java.io.*;
class GFG {
static Boolean divisibleBy20(String num)
{
// Get number with last two digits
int lastTwoDigits = Integer.parseInt(num.substring(num.length() - 2,
num.length() ));
// Check if the number formed by last two
// digits is divisible by 5 and 4.
return ((lastTwoDigits % 5 == 0) &&
(lastTwoDigits % 4 == 0));
}
// Driver Program
public static void main (String[] args)
{
String num = "63284689320";
if (divisibleBy20(num) == true)
System.out.println("Yes");
else
System.out.println("No");
}
}
// This code is contributed by Gitanjali.
Python3
# Python3 program to check if a large
# number is divisible by 20.
import math
def divisibleBy20(num):
# Get number with last two digits
lastTwoDigits = int(num[-2:])
# Check if the number formed by last two
# digits is divisible by 5 and 4.
return ((lastTwoDigits % 5 == 0 and
lastTwoDigits % 4 == 0))
# driver code
num = "63284689320"
if (divisibleBy20(num) == True):
print("Yes")
else:
print("No")
# This code is contributed by Gitanjali.
C#
// C# program to check if a large
// 'n' number is divisible by 20.
using System;
using System.Text;
class GFG
{
static bool divisibleBy20(String num)
{
// Get number with last two digits
int lastTwoDigits = Int32.Parse(num.Substring(2));
// Check if the number formed
// by last two digits is
// divisible by 5 and 4.
return ((lastTwoDigits % 5 == 0) &&
(lastTwoDigits % 4 == 0));
}
// Driver Code
static public void Main ()
{
String num = "63284689320";
if (divisibleBy20(num) == true)
Console.Write("Yes");
else
Console.Write("No");
}
}
// This code is contributed by Raj
PHP
Javascript
输出:
Yes