bzoj2154

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex> using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define re(i,a,b) for(i=a;i<=b;i++)
#define red(i,a,b) for(i=a;i>=b;i--)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const LL maxN=10000000LL;
const LL Mod=20101009LL; LL N,M;
LL ans; LL mu[maxN+],sum[maxN+];
LL prime[maxN+],tol;
bool isnotprime[maxN+];
inline void prepare()
{
LL i,j;
mu[]=;
re(i,,N)
{
if(!isnotprime[i]){mu[i]=-;prime[++tol]=i;}
for(j=;j<=tol && prime[j]*i<=N;j++)
{
isnotprime[prime[j]*i]=;
if(i%prime[j]==){mu[prime[j]*i]=;break;}
mu[prime[j]*i]=-mu[i];
}
}
re(i,,N) sum[i]=(sum[i-]+(mu[i]*i*i)%Mod)%Mod;
} inline LL F(LL x,LL y)
{
LL res=,e,last;
for(e=;e<=x;e=last+)
{
last=min(x/(x/e),y/(y/e));
upmin(last,x);
LL s=(sum[last]-sum[e-])%Mod;
LL t=((+(x/e))*(x/e)/%Mod)*((+(y/e))*(y/e)/%Mod)%Mod;//记住要多加括号
res=(res+s*t%Mod)%Mod;
}
return res;
} int main()
{
freopen("bzoj2154.in","r",stdin);
freopen("bzoj2154.out","w",stdout);
N=gll();M=gll();
if(N>M)swap(N,M);
prepare();
ans=;
LL d,last;
for(d=;d<=N;d=last+)
{
last=min(N/(N/d),M/(M/d));
upmin(last,N);
LL s=(d+last)*(last-d+)/%Mod;
LL t=F(N/d,M/d);
ans=(ans+s*t%Mod)%Mod;
}
ans=(ans%Mod+Mod)%Mod;
cout<<ans<<endl;
return ;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex> using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define re(i,a,b) for(i=a;i<=b;i++)
#define red(i,a,b) for(i=a;i>=b;i--)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const LL Mod=20101009LL;
const LL maxN=10000000LL; LL N,M; LL f[maxN+];
LL prime[maxN+],tol;
bool isnotprime[maxN+]; inline void prepare()
{
f[]=;
LL i,j;
re(i,,N)
{
if(!isnotprime[i]){prime[++tol]=i;f[i]=-i;}
for(j=;j<=tol && i*prime[j]<=N;j++)
{
isnotprime[i*prime[j]]=;
if(i%prime[j]==)
{
f[i*prime[j]]=f[i];
break;
}
f[i*prime[j]]=f[i]*f[prime[j]]%Mod;
}
}
} int main()
{
freopen("bzoj2154.in","r",stdin);
freopen("bzoj2154.out","w",stdout);
LL i;
N=gll();M=gll();
if(N>M)swap(N,M);
prepare();
LL ans=;
re(i,,N)
{
LL res=i;
res=res*((+(N/i))*(N/i)/%Mod)%Mod;
res=res*((+(M/i))*(M/i)/%Mod)%Mod;
res=res*f[i]%Mod;
ans=(ans+res)%Mod;
}
ans=(ans%Mod+Mod)%Mod;
cout<<ans<<endl;
return ;
}
来自:http://maijing3007.blog.163.com/blog/static/246120003201545101527359
bzoj2154的更多相关文章
- bzoj2154(莫比乌斯反演)
又是一道经典题. 1.学习了下O(n) 的做法. // // main.cpp // bzoj2154 // // Created by New_Life on 16/7/7. // Copyrigh ...
- 【BZOJ2154】Crash的数字表格(莫比乌斯反演)
[BZOJ2154]Crash的数字表格(莫比乌斯反演) 题面 BZOJ 简化题意: 给定\(n,m\) 求\[\sum_{i=1}^n\sum_{j=1}^mlcm(i,j)\] 题解 以下的一切都 ...
- BZOJ2154/BZOJ2693/Luogu1829 Crash的数字表格/JZPFAR 莫比乌斯反演
传送门--Luogu 传送门--BZOJ2154 BZOJ2693是权限题 其中JZPFAR是多组询问,Crash的数字表格是单组询问 先推式子(默认\(N \leq M\),所有分数下取整) \(\ ...
- 【bzoj2154】 Crash的数字表格
http://www.lydsy.com/JudgeOnline/problem.php?id=2154 (题目链接) 题意 给出${n,m}$,求$${\sum_{i=1}^n\sum_{j=1}^ ...
- BZOJ2154 Crash的数字表格 【莫比乌斯反演】
BZOJ2154 Crash的数字表格 Description 今天的数学课上,Crash小朋友学习了最小公倍数(Least Common Multiple).对于两个正整数a和b,LCM(a, b) ...
- bzoj2154||洛谷P1829 Crash的数字表格&&JZPTAB && bzoj3309 DZY Loves Math
bzoj2154||洛谷P1829 https://www.lydsy.com/JudgeOnline/problem.php?id=2154 https://www.luogu.org/proble ...
- 【BZOJ2693】jzptab & 【BZOJ2154】Crash的数字表格
题目 弱化版题目的传送门([BZOJ2154]Crash的数字表格) 加强版题目的传送门([BZOJ2693]jzptab) 思路&解法 题目是要求: \(\sum\limits_{i = 1 ...
- BZOJ2154: Crash的数字表格 & BZOJ2693: jzptab
[传送门:BZOJ2154&BZOJ2693] 简要题意: 给出n,m,求$\sum_{i=1}^{n}\sum_{j=1}^{m}LCM(i,j)$ 题解: 莫比乌斯反演(因为BZOJ269 ...
- Mobius反演定理-BZOJ2154
This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. 莫比乌斯定理(未 ...
随机推荐
- Storm拓扑的并行度(parallelism)介绍
Storm拓扑的并行度(parallelism)介绍 1.Storm分为3个主要实体,用于在Storm集群中运行拓扑 工作进程:Worker Process,也称为Worker ...
- maven+spring mvc初尝试
只是一个可以运行的例子,俺们来看看. 目录结构: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xml ...
- jQuery效果-淡入淡出
本文实现一个控制出现.消失.透明度的效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- LINQ 用法,返回结果不是在定义时取值,而是在调用时实时取值,有意思!
var names = new List<string> { "Nino o", "Alberto", "Juan", &quo ...
- struts2.1.*中再实现了一个servlet的方法
学习Struts2也有一段时间了,今天用Servlet写了一个验证码,然后搬到Struts2中,惊奇地发现Servlet无法访问,出现404错误!后来折腾了半天,终于找出原因了.这也算我学习中的一个重 ...
- USB描述符解析-->枚举.
枚举可以理解为主机按不定的顺序向USB设备讨要设备信息,好给它分配资源,若枚举不成功,就放弃分配资源,免得浪费资源.一般都是使用中断传输方式通信. 常用的描述符有以下几种:01H.设备描述符 02H ...
- Cortex-mo指令集
处理器使用的是ARMv6-M Thumb指令集,包括大量的32位的使用Thumb-2技术的指令.表7-22列出了Cortex-M0指令和它们的周期数.周期计数以零等待状态的系统为基准. 表7-22 ...
- apache ab工具对网站进行压力测试
Apache -- ab工具主要测试网站的(并发性能) 这个工具非常的强大. 基本语法 : cmd>ab.exe –n 请求总次数 -c 并发数 请求页面的url 进入到ab.ex ...
- 一步步启动linux
可以一步一步启动linux. 在Ubantu刚一启动时,按c健即进入Grub>提示符状态,在此状态下输入(我用的是Ubuntu 13) grub>linux /vmlinuz grub&g ...
- css快捷方式
本来是年前准备整理发布的,都搞定50%了,一篇万恶的<盗墓笔记:九幽将军>让我猪油蒙了心.....诶,不说了,搞一半就算了,最后还忘了保存,此刻只听得那一万只草某马呼啸而过... 言归正传 ...