AcWing 1205. 买不到的数目(数学)

Problem

十分经典的一道数学题,证明题。

证明方法比较繁琐,具体证明可以看这个博客

公式可以当作一个定理来记:x y 互质,则ax + by不能表示的最大数为 x * y - x - y

import java.io.*;

class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pw = new PrintWriter(System.out);
    static int a, b;
    
    public static void main(String []args) throws IOException{
        String []s = br.readLine().split(" ");
        a = Integer.parseInt(s[0]);
        b = Integer.parseInt(s[1]);
        pw.println(a * b - a - b);
        pw.flush();
        pw.close();
        br.close();
    }
}
发布了167 篇原创文章 · 获赞 3 · 访问量 3435

猜你喜欢

转载自blog.csdn.net/qq_43515011/article/details/104186799