many sum

链接:https://ac.nowcoder.com/acm/contest/879/G
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

输入描述:

第一行三个整数 N,A1,M

输出描述:

第一行一个整数,表示答案。
示例1

输入

复制

10 10 313

输出

复制

441

备注:

1≤N≤2×10^6,0≤A1,M<10^4
通过此题的同学,不妨来想一些如果N=2×107的时候该怎么做呢? d|i为“d整除i”或“i被d整除”,可看作i%d==0,也就是需要找i所有的因子。
筛因子法利用逆向思维,枚举因子的倍数反向加入到i中。
一开始存表预处理1~n因子T了,这里找到直接加入Bi即可,一步到位。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; int a[],b[]; int main()
{
int t,k,i,j;
ll n,m;
scanf("%d%d%d",&n,&a[],&m);
for(i=;i<=n;i++){
a[i]=(a[i-]+*i)%m;
}
for(i=;i<=n;i++){
for(j=i;j<=n;j+=i){ //筛因子
b[j]+=a[i];
}
}
ll ans=;
for(i=;i<=n;i++){
ans^=b[i];
}
printf("%lld\n",ans);
return ;
}

牛客月赛 G-many sum(筛因子)的更多相关文章

  1. 牛客网——G送分了(py)

    链接:https://www.nowcoder.net/acm/contest/74/G来源:牛客网 题目描述 杭州人称傻乎乎的人为62,而嘟嘟家这里没有这样的习俗. 相比62,他那里的人更加讨厌数字 ...

  2. 牛客网——G大水题

    链接:https://www.nowcoder.net/acm/contest/75/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...

  3. 牛客小白月赛2 G 文 【模拟】

    链接:https://www.nowcoder.com/acm/contest/86/G来源:牛客网 题目描述 Sεlιнα(Selina) 开始了新一轮的男友海选.她要求她的男友要德智体美劳样样都全 ...

  4. 牛客小白月赛12 D 月月给华华出题 (欧拉函数,数论,线筛)

    链接:https://ac.nowcoder.com/acm/contest/392/D 来源:牛客网 月月给华华出题 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 131072K, ...

  5. 牛客小白月赛12C (线性筛积性函数)

    链接:https://ac.nowcoder.com/acm/contest/392/C来源:牛客网 题目描述 华华刚刚帮月月完成了作业.为了展示自己的学习水平之高超,华华还给月月出了一道类似的题: ...

  6. 牛客小白月赛6 G 指纹锁 set的自动排序 模板

    链接:https://www.nowcoder.com/acm/contest/136/G来源:牛客网 题目描述     HA实验有一套非常严密的安全保障体系,在HA实验基地的大门,有一个指纹锁.   ...

  7. 牛客小白月赛 G 异或 找规律

    链接:https://www.nowcoder.com/acm/contest/135/G来源:牛客网 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apoj ...

  8. 牛客小白月赛12 C 华华给月月出题 (积性函数,线性筛)

    链接:https://ac.nowcoder.com/acm/contest/392/C 来源:牛客网 华华给月月出题 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K, ...

  9. 牛客多校第四场 G Maximum Mode

    链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value tha ...

随机推荐

  1. samba服务器的搭建和配置

    案例: 公司有两个部门, sales / market . 分别有成员 jack / tom 和 zhang / shen . 公司需求是这样的, 本部门资料禁止其他部门访问, 本部门成员之间不能干扰 ...

  2. spring-data-redis RedisTemplate操作

    使用RedisTemplate来对对象.String等做缓存处理 首先定义一个对象并重写toString方法 public class UserInfo implements Serializable ...

  3. 窥探 Swift 之别具一格的 Struct 和 Class

    说到结构体和类,还是那句话,只要是接触过编程的小伙伴们对这两者并不陌生.但在Swift中的Struct和Class也有着令人眼前一亮的特性.Struct的功能变得更为强大,Class变的更为灵活.St ...

  4. centos下安装wordpress

    https://www.jianshu.com/p/2439dc2187b2 https://blog.csdn.net/liuhelong/article/details/79924014

  5. plsql连接oracle 64位数据库ORA-12514错误

    今天帮小师妹还原数据库,删除表空间的时候把数据库搞坏了,plsql连接时报了 ORA-12514: TNS:listener does not currently know of service re ...

  6. interceptors

    <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean ...

  7. React之jsx语法特性

    jsx 语法,直接可以在js中使用html标签. 还可以通过花括号的形式,在html标签中,写js表达式. <div> { 1 + 2 } hello,world! </div> ...

  8. elasticsearch _source字段的一些说明

    _source field The _source field contains the original JSON document body that was passed at index ti ...

  9. 2018.3.1 RF module distance test part II-

    1 Test  circuit diagram 2  Test demo 3 Test record 4  Test  analysis 5 Test results and discussion E ...

  10. 前端多媒体(4)—— video标签全面分析

    测试地址:https://young-cowboy.github.io/gallery/html5_video/index.html 属性 一些属性是只读的,一些属性是可以修改从而影响视频播放的. a ...