📅  最后修改于: 2023-12-03 14:49:26.863000             🧑  作者: Mango
GeeksforGeeks CP 直播课程是一个非常好的竞争性编程学习平台,提供丰富的教程和实践机会,可以帮助程序员快速提升编程能力与竞争素质。
# Python code to find remainder
# when large numbers are divided
# In this program, we will find the remainder
# of two very large numbers when one number is
# divided by another.
# function to calculate remainder
def findRemainder(dividend, n):
# If the dividend is smaller than
# the divisor, the remainder is the
# dividend itself
if dividend < n:
return dividend
# reducing the dividend with each step
# and taking the remainder with divisor
# till dividend is smaller than divisor
i = 1
temp = n
while temp <= dividend:
temp = temp << 1
i = i << 1
temp = temp >> 1
i = i >> 1
return dividend - temp + findRemainder(dividend - temp, n)
# main function
if __name__ == '__main__':
dividend = 1000000000000
divisor = 17777
print(findRemainder(dividend, divisor))
// Java code to find remainder
// when large numbers are divided
// In this program, we will find the remainder
// of two very large numbers when one number is
// divided by another.
import java.util.*;
public class Main {
// function to calculate remainder
public static int findRemainder(int dividend, int n) {
// If the dividend is smaller than
// the divisor, the remainder is the
// dividend itself
if (dividend < n) {
return dividend;
}
// reducing the dividend with each step
// and taking the remainder with divisor
// till dividend is smaller than divisor
int i = 1;
int temp = n;
while (temp <= dividend) {
temp = temp << 1;
i = i << 1;
}
temp = temp >> 1;
i = i >> 1;
return dividend - temp + findRemainder(dividend - temp, n);
}
// main function
public static void main(String[] args) {
int dividend = 1000000000;
int divisor = 17;
System.out.println(findRemainder(dividend, divisor));
}
}
以上是两个示例代码,用于说明如何在 GeeksforGeeks CP 直播课程上编写基本算法。这些代码具有简单易懂、详细说明每一个细节等特点。这些特点是 GeeksforGeeks CP 直播课程中曾讲解过的。