洛谷 P2260 [清华集训2012]模积和 || bzoj2956
2024-09-04 16:21:02
https://www.lydsy.com/JudgeOnline/problem.php?id=2956
https://www.luogu.org/problemnew/show/P2260
暴力推式子即可
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll md=;
ll n,m,ans,a1,a2;
ll Mod(ll x,ll md=md)
{
if(x>=) return x%md;
else if(x%md==) return ;
else return md+x%md;
}
ll calc(ll x)
{
return (x)*(x+)%md*(*x+)%md*%md;
}
int main()
{
ll i,j;
scanf("%lld%lld",&n,&m);
if(n>m) swap(n,m); // {
// ll ams=0;
// for(ll i=1;i<=n;i++)
// for(ll j=1;j<=m;j++)
// if(i!=j)
// ams=Mod(ams+(n-n/i*i)*(m-m/j*j));
// printf("%lld",ams);
// return 0;
// } for(i=;i<=n;i=j+)
{
j=n/(n/i);
a1=Mod(a1+Mod((i+j)*(j-i+)/)*(n/i));
}
for(i=;i<=m;i=j+)
{
j=m/(m/i);
a2=Mod(a2+Mod((i+j)*(j-i+)/)*(m/i));
}
//printf("a%lld %lld\n",a1,a2); ans=Mod(ans+n*n%md*m%md*m%md);
ans=Mod(ans-n*n%md*a2%md);
ans=Mod(ans-m*m%md*a1%md);
ans=Mod(ans+a1*a2%md); ans=Mod(ans-n*n%md*m%md);
{
ll t=;
for(i=;i<=n;i=j+)
{
j=min(n,m/(m/i));
t=Mod(t+Mod((i+j)*(j-i+)/)*(m/i));
}
ans=Mod(ans+n*t%md);
}
ans=Mod(ans+m*a1%md);
{
ll t=;
for(i=;i<=n;i=j+)
{
j=min(n/(n/i),m/(m/i));
t=Mod(t+Mod(calc(j)-calc(i-))*(n/i)%md*(m/i));
}
//printf("t%lld\n",t);
ans=Mod(ans-t);
} printf("%lld",ans);
return ;
}
最新文章
- XE3随笔17:实例 - 模拟 Google 搜索
- 【数据压缩】Huffman编码
- Mango Weekly Training Round #6 解题报告
- 青瓷qici - H5小游戏 抽奖机 1 素材
- Reactor模式(反应器模式)
- 25045操作标准子程序集41.C
- Objective-C基础笔记(2)@property和@synthesize
- Exception in thread &;quot;main&;quot; java.lang.IllegalArgumentException
- ER模型的学习
- EF查询百万级数据的性能测试--多表连接复杂查询
- NetworkManager 冲突
- Linux内核数据结构之kfifo详解
- Java远程连接redis, 报错 Connection refused: connect
- OP社区相关
- linux---文件颜色含义
- 浏览器Hack演示
- MyBatis JavaType JdbcType
- leetcode python找不同
- [HDU4089]Activation(概率DP)
- poj 1962(并查集+带权更新)