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

这道题考察的就是余数的性质 负数的余数 还要加上避免两数之和超出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);
}
}

浙公网安备 33010602011771号