跳到正文

个人记录

集训day1

yyds114514约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年6月16日
篇幅
约 2 分钟

版本

  1. v1当前

Day 1:

我不会C++,一共做了这些题: P1226 B3908 P8072 B3919 P1047 P5727 P1427 P1428。其中最有收获的Java实现:

Java
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long p = scanner.nextLong();
        
        long result = modExp(a, b, p);
        
        System.out.printf("%d^%d mod %d=%d\n", a, b, p, result);
        
        scanner.close();
    }
    
    private static long modExp(long base, long exp, long mod) {
        long result = 1;
        base = base % mod;
        
        while (exp > 0) {
            if ((exp & 1) == 1) {
                result = (result * base) % mod;
            }
            exp >>= 1;
            base = (base * base) % mod;
        }
        return result;
    }
}
原文