https://zh.wikipedia.org/wiki/%E8%BC%BE%E8%BD%89%E7%9B%B8%E9%99%A4%E6%B3%95 取模也是一样的,就当多减几次. 在欧几里得最初的描述中,商和余数是通过连续的减法来计算的,即从rk−2中不断减去rk−1直到小于rk−1.一个更高效的做法是使用整数除法和模除来计算商和余数: rk ≡ rk−2 mod rk−1 在欧几里得定义的减法版本,取余运算被减法替换 while (b!=0) { if (a>b) a=a-b; else…
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 <= n <= 200000\), 如果至多删除其中的一个数之后该序列为严格上升序列,那么称原序列为几乎严格上升序列. 现在每次将序列中的任意数字变成任意数字,问最少要操作几次才能将序列变成几乎严格上升子序列. 思路: 如果不考虑删除,求让整个序列都变成严格上升子序列的次数 求出\(序列a_i - i\)…
2018-03-11 http://codeforces.com/contest/946/problem/D D. Timetable time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan is a student at Berland State University (BSU). There are n days in…
题: OvO http://codeforces.com/contest/946/problem/E CF 946E 解: 记读入串为 s ,答案串为 ans,记读入串长度为 len,下标从 1 开始. 分三种情况讨论 1.数字位数为奇数,设数字位数为 len,则输出 ( len-1 ) 个 9 即可 ,最低位为 或者,其他位为 ,(即 100001,100 这些形式),记数字位数为 len,则输出 ( len-2 ) 个 9 即可 3.数字位数为偶数,而并非是第二种情况,那么进行一次 dfs…
D. Timetable time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have s…
链接: https://codeforces.com/contest/1238/problem/A 题意: You are given two integers x and y (it is guaranteed that x>y). You may choose any prime integer p and subtract it any number of times from x. Is it possible to make x equal to y? Recall that a pr…
题目链接:https://codeforces.com/contest/1359/problem/E 题意 有一大小为 $k$ 的数组,每个元素的值在 $[1,n]$ 间,若元素间两两不等,问有多少数组对于任意非负整数 $x$ 满足: $x\ \%\ a_{1} \ \%\  a_{2} \ \%\  ...  \ \%\  a_{k} = x \ \%\  a_{p1} \ \%\  a_{p2} \ \%\  ...  \ \%\  a_{p_k}$ 其中,$p$ 为 $k$ 的任一种排列,…
题意:有$n$个孩子,第$i$个孩子有$k[i]$件想要的礼物,第$j$个礼物为$a[i][j]$,现在随机挑一个孩子,从他想要的礼物里面随机挑一个,然后送给另一个孩子$($这个孩子可以和第一个孩子是同一个人$)$,问你送的这个礼物在后一个孩子愿望单里的概率. 思路:求出每件礼物出现的次数$cnt[]$,挑出第一个孩子的概率为$\frac{1}{n}$,在他的愿望单里挑出一件礼物的概率为$\frac{1}{k[i]}$,挑出另一个孩子的概率也是$\frac{1}{n}$,挑出的第一个孩子的每件礼…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec Problem Description Input Output The only line should contain the minimal number of days required for the ship to reach the point (x2,y2)(x2,y2). If it…
Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec Problem Description Input The input contains a single line consisting of 2 integers N and M (1≤N≤10^18, 2≤M≤100). Output Print one integer, the total n…