HDU6128Inverse of sum
来源:互联网 发布:交易圣经知乎 编辑:程序博客网 时间:2024/05/01 07:07
题目链接
题意
存在一个长度为
分析
题目中已经提示了0没有逆元,即碰到0跳过即可。 先对题目中的同余式进行化简,获得
进一步化简得到
此前一直想要通过二次剩余硬搞过去,然而无奈一直T,大概初学二次剩余,方法太渣。最后参考网上大牛做法后得知可以两边同乘一个
于是只要通过快速乘法枚举每个
代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#include<fstream>using namespace std;#define LL long long#define MAXN 100100LL a[MAXN];map<LL,int> num;map<LL,int> cnt;LL multi(LL a,LL b,LL p){ LL ret=0; while(b){ if(b&1) ret=(ret+a)%p; b>>=1; a=(a+a)%p; } return ret;}int main(){ int T,n; LL p,ans; cin>>T; while(T--){ scanf("%d %I64d",&n,&p); num.clear(); cnt.clear(); ans=0; for(int i=0;i<n;++i){ scanf("%I64d",&a[i]); if(!a[i]) continue; if(multi(multi(a[i],a[i],p),3,p)) ans-=cnt[a[i]]; LL val=multi(multi(a[i],a[i],p),a[i],p); ans+=num[val]++; cnt[a[i]]++; } printf("%I64d\n",ans); }}
阅读全文
0 0
- HDU6128Inverse of sum
- Sum of Factorials
- Sum of Factorials
- Sum Of SubRectangular Parallelepiped
- HDU3022:Sum of Digits
- HDU3022:Sum of Digits
- lucky sum of digit
- 【模拟】Sacrament of Sum
- 【Hash】Sacrament of Sum
- Sum of Factorials
- hdu4432 Sum of divisors
- Game of Sum
- Sum of absolute differences
- denim1: sum of subsets
- Sum of a tree
- Sum of a tree
- Sum of mod
- hdu4432 - Sum of divisors
- 学生选课统计练习java
- UI自动化体系建设的创新实践
- 404,500等HTTP状态码表示的含义
- Oracle学前班
- Linux功耗管理(7)_Wakeup events framework
- HDU6128Inverse of sum
- Oracle数据库exp与expdp方式导入导出时改变数据库表空间及用户信息
- caffe自定义神经层
- codeforces 24C 找规律
- Python 字符串函数
- VS2010/MFC MFC 常用类:定时器 Timer
- 「网络流 24 题」运输问题
- 任务进度规划(每日更新)
- 73. Set Matrix Zeroes