use num_bigint::BigInt;
use num_traits::{Zero, ToPrimitive};
fn main() {
// Example BigInt value
let big_number = BigInt::parse_bytes(b"12345678901234567890123456789123", 10).unwrap();
// Get the last digit
let last_digit = get_last_digit(&big_number);
// Print the result
println!("The last digit of {} is {}", big_number, last_digit);
}
// Function to get the last digit of a BigInt
fn get_last_digit(num: &BigInt) -> u8 {
if num.is_zero() {
return 0; // Special case: last digit of 0 is 0
}
// Calculate the remainder when dividing by 10
(num % 10u8).to_u8().unwrap()
}
/*
run:
The last digit of 12345678901234567890123456789123 is 3
*/