解题思路:
#include <iostream> using namespace std; typedef long long ll; const int N = 1e5 + 10; ll n, k; ll a[N], cnt[N]; int main() { cin >> n >> k; for (int i = 1; i <= n; i ++ ){ scanf("%d",&a[i]); a[i] += a[i - 1]; } ll res = 0; for (int i = 1; i <= n; i ++ ) { res += cnt[a[i] % k]; if (a[i] % k == 0) res ++ ; cnt[a[i] % k] ++ ; } cout << res; }
注意事项:
参考代码:
0.0分
1 人评分
C二级辅导-阶乘数列 (C语言代码)浏览:638 |
矩形面积交 (C语言代码)浏览:1541 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:1055 |
字符串对比 (C语言代码)浏览:1454 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:613 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)万恶的long long浏览:902 |
剪刀石头布 (C语言代码)浏览:791 |
矩阵加法 (C语言代码)浏览:1759 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1166 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:608 |