【蓝桥杯算法】2026/4/9 余数的性质

image

这道题考察的就是余数的性质 负数的余数 还要加上避免两数之和超出int的范围


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int x=sc.nextInt();
        //0 1 2 3 4 5
        /**
         * 2 - 4 = 4
         * 就相当于 (2-4)%6=4
         */
        int ans=0;
        for (int i = 0; i < n; i++) {
            int ai=sc.nextInt();
            x=(x%m+ai%m)%m;
            if(x==0)ans++;
        }
        System.out.println(ans);

    }
}
posted @ 2026-04-09 16:23  Jwwind  阅读(9)  评论(0)    收藏  举报