题意:

定义一年为 mmm 个月,每个月 ddd 天 ,每周有 www 天。

找到有多少对 (x,y)(x,y)(x,y) 满足 xxx 月的第 yyy 天 和 yyy 月的第 xxx 天是同一星期。

题解:

题目就是求 ((x−1)⋅d+y)%m==((y−1)⋅d+x)%m((x-1) \cdot d + y ) \% m == ((y-1) \cdot d + x ) \% m((x−1)⋅d+y)%m==((y−1)⋅d+x)%m

移项化简可得到:(d−1)⋅(x−y)%m==0(d-1) \cdot (x-y) \% m==0(d−1)⋅(x−y)%m==0 ,(x>y)(x>y)(x>y)

设 w=m/gcd(d−1,m)w= m/gcd(d-1,m)w=m/gcd(d−1,m) ,那么 (x−y)(x-y)(x−y) 必须是www 的倍数才能使得上述式子满足。

因为x,yx,yx,y 交换后,要保证有有这个月和这一天,所以直接取 m=min(m,d)m=min(m,d)m=min(m,d).

那么当x=mx=mx=m时,有 (m−1)/w(m-1)/w(m−1)/w 个 ,x=m−1x=m-1x=m−1时,有 (m−2)/w(m-2)/w(m−2)/w 个。。。。以此类推

即求 ∑i=1m−1i/w\sum\limits_{i=1}^{m-1} i/wi=1∑m−1​i/w , 设 a=m−1/wa=m-1/wa=m−1/w ,只要求 aaa 有多少个,那么 剩下 a−1a−2a−3....1a-1 \quad a-2 \quad a-3 ....1a−1a−2a−3....1 都是www 个。

那么答案就是 a⋅((m−1)%w+1)+(a−1)⋅a/2⋅wa \cdot ((m-1) \% w+1) + (a-1) \cdot a/2 \cdot wa⋅((m−1)%w+1)+(a−1)⋅a/2⋅w

代码:

#pragma GCC diagnostic error "-std=c++11"
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<ctime>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const int MAXN=2e5+5;
const int inf=0x3f3f3f3f;
int main()
{int t;cin>>t;while(t--){ll m,d,w;cin>>m>>d>>w;if(d==1){printf("0\n");continue;}ll gd=__gcd(d-1,w);ll res=w/gd;ll maxx=min(m,d);ll ans=0;ll x=(maxx-1)/res;ll y=(maxx-1)%res+1;ans=x*y;if(x-1>1) ans+=(x-1)*x/2*res;else if(x-1==1) ans+=(x-1)*res;printf("%lld\n",ans);}
}

CodeForces - 1389E E. Calendar Ambiguity(数学)相关推荐

  1. E. Calendar Ambiguity(思维数论)

    E. Calendar Ambiguity(思维&数论) 思路:思维&数论. 考虑 i i i月 j j j日 = j =j =j月 i i i日. 即: { [ ( i − 1 ) ...

  2. Educational Codeforces Round 11A. Co-prime Array 数学

    地址:http://codeforces.com/contest/660/problem/A 题目: A. Co-prime Array time limit per test 1 second me ...

  3. 【CodeForces - 304B】Calendar (前缀和,水题)

    题干: Calendars in widespread use today include the Gregorian calendar, which is the de facto internat ...

  4. codeforces The Artful Expedient(数学思维题)

    题目链接: http://codeforces.com/contest/869/problem/A 题目大意: 给你一个n,分别输入两组n个数字,如果这两组数字两两异或的结果与两组数字中的某一个数字相 ...

  5. CodeForces - 1213A Chips Moving (思维 数学)

    CodeForces - 1213A Chips Moving 题目: You are given n chips on a number line. The i-th chip is placed ...

  6. 【CF1389】E. Calendar Ambiguity(数论)

    题目链接:https://codeforces.com/problemset/problem/1389/E 分析 根据所给条件,可以写出: ( x − 1 ) d + y ≡ ( y − 1 ) d ...

  7. Codeforces 813B The Golden Age(数学+枚举)

    题目大意:如果一个数t=x^a+y^b(a,b都是大于等于0的整数)那就是一个unlucky数字.给你x,y,l,r(2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18),求出l到 ...

  8. CodeForces - 1307B Cow and Friend(数学+思维)

    题目链接:点击查看 题目大意:在二维平面上,要求从点 ( 0 , 0 ) 到点 ( x , 0 ) 处,每次只能行走给出的路径长度,问最少需要走几次才能到 题目分析:读完题后首先想到的是三角形,如果想 ...

  9. CodeForces - 1301C Ayoub's function(数学)

    题目链接:点击查看 题目大意:规定函数 f(s) 为01字符串 s 中至少包含一个 1 的所有子串的数量,比如 f(10101) = 12 ,其中十二个子串分别为(1,2),(1,3),(1,4),( ...

  10. CodeForces - 765D Artsem and Saunders(数学化简+构造+思维)

    题目链接:点击查看 题目大意:给出一个序列f(x),要求我们构造出两个序列g(x)和h(x),满足: g(h(x))=x g(x)定义域[1,n],值域[1,m] h(g(x))=f(x) h(x)定 ...

最新文章

  1. 【Java 线程的深入研究3】最简单实例说明wait、notify、notifyAll的使用方法
  2. 微型计算机dec al,微机原理复习知识点
  3. 【Paddle】Anaconda安装PaddlePaddle和PaddleX教程
  4. ansys如何删除线_绘画新手不懂如何用ps提取线稿?教你用PS提取自己喜欢的线稿!...
  5. 剪切文件_转录组测序技术和结果解读(十六)——可变剪切
  6. 高德上线“家人地图”惹争议 官方回应:用户确认授权后才能使用
  7. 猿辅导 python_关于猿辅导机器学习项目ytk-learn和ytk-mp4j分布式机器学习库
  8. Linux系统的镜像文件iso下载地址
  9. pdf文件解密去水印加书签
  10. 罗比机器人说明书_罗比_机器人人物_我要机器人
  11. 华南农业大学C语言程序设计(实验六)
  12. 匿名发送邮件python_Python 发送邮件的四种方法汇总
  13. YOLOv7全文翻译
  14. linux中inotify+unison实现数据双向实时同步
  15. Requirement already satisfied解决办法
  16. BNUOJ 4140 Video Game Troubles
  17. 1142 Maximal Clique
  18. EPICS简单实例2 -- subroutine记录(sub)介绍与使用
  19. ts中any 、unKnown的区别
  20. java根据拼音获取声调_Pinyin4j的基本用法 获得拼音的声调

热门文章

  1. Android9.0 HAL 层开发
  2. pegasus 简介
  3. 使用 HTML、CSS 和 JavaScript 定制私人版的刮刮乐【一看就会】
  4. 计算机网络辅助英语写作,基于计算机网络的英语写作教学
  5. 十大排序算法笔记(C语言)(一)选择排序、冒泡排序、插入排序、希尔排序、快速排序
  6. 使用docker搭建个人博客
  7. 在c语言万年历中怎么添加节日,用C实现简单万年历
  8. chemdraw如何改中文_如何修改ChemDraw的默认输出格式
  9. C#+ArcEgine开发(2)添加shp和lyr文件
  10. 高级php工程师需要掌握的知识点