传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5970

∑i=1n∑j=1m⌊(i∗j)f(i,j)⌋=∑j=1m∑i=1j∑k=0c−1∑l=0i+j∗(k+l∗c)<=n⌊(i+j∗(k+l∗c))c∗x∗x⌋=∑j=1m∑i=1j∑k=0c−1∑l=0i+j∗(k+l∗c)<=n⌊(i+j∗k)∗jc∗x∗x⌋+l∗j∗jx∗x

\sum_{i=1}^n \sum_{j=1}^m \lfloor \frac{(i*j)}{f(i,j)}\rfloor= \sum_{j=1}^m \sum_{i=1}^j \sum_{k=0}^{c-1} \sum_{l=0}^{i+j*(k+l*c)

//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;#define pi acos(-1)
#define s_1(x) scanf("%d",&x)
#define s_2(x,y) scanf("%d%d",&x,&y)
#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define fOR(n,x,i) for(int i=n;i>=x;i--)
#define fOr(n,x,i) for(int i=n;i>x;i--)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
#define ll long long
#define mp make_pair
#define pb push_back
typedef pair<long long int,long long int> ii;
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=1e3+10;
const int maxx=600005;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=1e9+7;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;//http://www.cnblogs.com/phile/p/6391465.html
LL n,m,p;
LL Fc[maxn][maxn];
LL Fcx[maxn][maxn];void f(LL x,LL y)
{LL tx=x,ty=y;LL c=0;while(y>0){c+=1;LL t=x%y;x=y;y=t;}Fc[tx][ty]=c;Fcx[tx][ty]=c*x*x;}void init()
{for(LL j=1; j<=666; j++){for(LL i=0; i<=j; i++){f(i,j);}}
}
void solve()
{scanf("%I64d%I64d%I64d",&n,&m,&p);LL ans=0;FOR(1,m,j){for(int i=1;i<=j&&i<=n;i++){for(int k=0;k<Fc[i][j];k++){if(i+k*j>n) break;LL b=(i+j*k)*j/Fcx[i][j];LL d=Fc[i][j]*j*j/Fcx[i][j];LL t=(n-(i+j*k))/(Fc[i][j]*j)+1;//倍数ans=(ans+b*t%p+(t-1)*t/2%p*d%p)%p;}}}print(ans);
}int main()
{init();int t;scan_d(t);W(t--){solve();}
}

hdu 5970 最大公约数相关推荐

  1. HDU 5970 CCPC2016合肥 求等差数列整除整数下取整求和

    先来大宝贝 a 公差 b 初始项 c 除数 n 项数 long long get(long long a,long long b,long long c,long long n){if (n<= ...

  2. Tailwind Sidebar

    侧边栏 sidebar https://codepen.io/junchow/pen/GRoJPeo?editors=1000 <link href="https://unpkg.co ...

  3. HDU 2503 a/b + c/d(最大公约数与最小公倍数,板子题)

    话不多说,日常一水题,水水更健康!┗|`O′|┛ 嗷~~ a/b + c/d Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768 ...

  4. HDU 5050 Divided Land (二进制上的最大公约数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5050 题面: Divided Land Time Limit: 8000/4000 MS (Java/ ...

  5. (hdu step 2.1.1)最小公倍数(使用最大公约数来辅助求最小公倍数)

    题目: 最小公倍数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...

  6. 数学--数论--HDU 2104 丢手绢(离散数学 mod N+ 剩余类 生成元)+(最大公约数)

    The Children's Day has passed for some days .Has you remembered something happened at your childhood ...

  7. 2018 Spring Team Contest D HDU - 6023、HDU - 6024、HDU - 6025 、HDU - 6027 、HDU - 6029

    HDU - 6023  //编译错误不算罚时 #include<cstdio> #include<cstring> #include<iostream> #incl ...

  8. 欧拉函数和最大公约数的组合应用

    这种问题一般都是给出限制条件:给你一个数N(N一般很大),使得在1~N之间能够找到X使得X满足gcd( X ,  N  ) >= M,然后求解相关的问题.          分析:这是一种统计类 ...

  9. GCD Game HDU - 7061

    GCD Game HDU - 7061 题意: 有n个数ai,两个人轮流操作,每次选择一个数ai,再人选一个x(1<=x<ai),然后用gcd(ai,x)代替ai 谁先不能操作谁先输掉比赛 ...

最新文章

  1. 哥伦比亚大学AI实验室主任Hod Lipson:阻碍无人驾驶技术发展的7个误区
  2. 零拷贝(Zero Copy)
  3. 【SQLAlchemy】is not bound to a Session; attribute refresh operation cannot proceed
  4. 玩转C#控件-常用控件属性
  5. 动画片动漫迷<未来的未来>高清图片壁纸
  6. linux常用命令-文件处理命令
  7. python中的私有方法_Python: 内置私有方法
  8. iphone:点击背景隐藏键盘
  9. 小伙伴要我给他介绍一些非常酷炫而有趣又容易上手的前端框架
  10. 基于 Robot Framework 实现网络自动化测试
  11. MC官方模板的分析Day1
  12. 【技术干货】详解BGP4+的负载分担
  13. 开发项目中,360浏览器遇到的一个坑
  14. C++实现的BP神经网络(代码与详解)
  15. 嵌入式系统设计的核心技术
  16. leetcode.1402做菜顺序
  17. Magisk Delta工具安装教程
  18. Android音频录制方案,Android录音,录制其他App播放的声音
  19. 最新朋友圈社区系统源码+UI很不错的
  20. 数字电路设计中亚稳态与MTBF

热门文章

  1. 如何发现异常商业数据?达摩院用这套算法
  2. 【kratos】kratos 框架使用新的,还是非常好的技术框架,还要继续学习,掌握了proto 文件的使用、wire的使用就方便了。
  3. 文件和文件流——文件转码失败conversion failed: input document is null after loading
  4. 雅虎都沦落到卖核心资产,为何马云孙正义巴菲特还抢着买
  5. 图片传输中的转码问题
  6. linux tcp repair及tcp热迁移
  7. 我国超级计算机第一名是,中国蝉联超级计算机冠军,美国跌出前三
  8. bootstrap4.3.1 导航栏鼠标悬停下拉显示
  9. OCI : ORA-24333: zero iteration count
  10. 如何在Microsoft Edge中更改主页