这道题是道数论题,如果想对了的话会很快。

因为这道题实在是没有什么知识点,所以我直接上代码,代码上有很详细的注释:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[]={},t; //a为桶排序数组
int main(){
std::ios::sync_with_stdio();//读入输出加速
cin>>t;//测试数据的个数
while(t--){
long long k,n; //k为模,n为数列的长度
cin>>k>>n; //输入
memset(a,,sizeof(a)); //清空a数组
long long sum=; //sum表示前缀和的累加mod K的结果
long long x;//x表示当前输入的数
long long ans=; //ans表示结果
for(int i=;i<=n;i++){ //循环表示当前读到的数列元素的位置
cin>>x; //输入该元素x
sum=(sum+x)%k; //累计前缀和并覆盖sum
a[sum%k]++; //桶排序,表示有多少同余的数
}
for(int i=;i<k;i++){ //循环访问排序结果
ans+=a[i]*(a[i]-)/;// 如果这个余数i有很多个情况,因为里面保存的是1-?的和mod k。
//a[i]中任意两个相减都代表前缀和相减,代表的是一个1-n的子区间,例如:1,2,3,4,因为必须上一个区间比减去的区间大才可以
//进行相减操作所以只能从1开始减2,3,4.从2开始减3,4.类似地计算这类排列的情况为:n*(n-1)/2
//这样的话可以计算出来合法的子序列的方案和。
}
cout<<ans<<endl;//加上本来余数就是零的序列
}
}

2644. 数列 (Standard IO)的更多相关文章

  1. 1001. 温度转换 (Standard IO)

    1001. 温度转换 (Standard IO) 时间限制: 1000 ms  空间限制: 262144 KB  具体限制   题目描述 将输入的华氏温度转换为摄氏温度.由华氏温度F与摄氏温度C的转换 ...

  2. JZOJ 2137. 【GDKOI2004】城市统计 (Standard IO)

    2137. [GDKOI2004]城市统计 (Standard IO) Time Limits: 1000 ms  Memory Limits: 128000 KB  Detailed Limits  ...

  3. JZOJ 5326. LCA 的统计 (Standard IO)

    5326. LCA 的统计 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description Input Output S ...

  4. JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)

    5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...

  5. JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)

    5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...

  6. JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)

    5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...

  7. JZOJ 5257. 小X的佛光 (Standard IO)

    5257. 小X的佛光 (Standard IO) Time Limits: 2000 ms Memory Limits: 524288 KB Description Input Output Sam ...

  8. JZOJ 5258. 友好数对 (Standard IO)

    5258. 友好数对 (Standard IO) Time Limits: 1000 ms Memory Limits: 524288 KB Detailed Limits Description I ...

  9. JZOJ 1349. 最大公约数 (Standard IO)

    1349. 最大公约数 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 小菜的妹妹小诗就要读小学了!正所谓 ...

随机推荐

  1. CSRF相关

    CSRF原理 第一次获取页面的时候浏览器返回一个随机字符串,之后提交数据的时候需要把到这个字符串去提交,不然会报错 返回的时候还会把这个字符串放到cookie里面, 使用form提交时候: {% cs ...

  2. Metasploitable2使用指南

    Metasploitable2使用指南 Metasploitable2 虚拟系统是一个特别制作的ubuntu操作系统,本身设计作为安全工具测试和演示常见漏洞攻击.版本2已经可以下载,并且比上一个版本包 ...

  3. CSS样式表能否控制文字禁止选择,复制, 焦点

    div中禁止文字被选择 在做div的点击计数事件时,遇到一个小问题. 因为div里面有文字,所以当点击多次时,特别是鼠标点的比较快的时候,文字会被选中. 查了下,用css和javascript可以实现 ...

  4. 2019-9-2-win10-uwp-兴趣线

    title author date CreateTime categories win10 uwp 兴趣线 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 17 ...

  5. 04.Linux系统-Zabbix监控服务安装部署

    一.环境准备 操作系统:CentOS_Server_7.5_x64_1804.iso 部署组件:Zabbix 二.操作步骤: Zabbix_Server安装部署 2.0.安装依赖组件 [root@lo ...

  6. linux的iptables设置---防火墙

    1.首先介绍一下指令和相关配置文件 启动指令:service iptables start 重启指令:service iptables restart 关闭指令:service iptables st ...

  7. MetaException(message:For direct MetaStore DB connections, we don't support retries at the client level.)

    在mysql中执行以下命令:  drop database hive;  create database hive;  alter database hive character set latin1 ...

  8. session有效时间

    request.getSession().setMaxInactiveInterval(-1);//session不失效 request.getSession().setMaxInactiveInte ...

  9. java基础复习(三)

    一.运算符 1.算术运算符 1) 加法(+) 加法   正号  字符串拼接 2) 减法(-) 减法 负号 3) 乘法 (*) 乘法 4) 除法(/) 除法 整数(小数)相除的例子 10/3 =3:   ...

  10. Codeforces 776E: The Holmes Children (数论 欧拉函数)

    题目链接 先看题目中给的函数f(n)和g(n) 对于f(n),若自然数对(x,y)满足 x+y=n,且gcd(x,y)=1,则这样的数对对数为f(n) 证明f(n)=phi(n) 设有命题 对任意自然 ...