n对mod求模,它的值在0到mod-1之间,如果要求模整除的时候转化成mod可以用下面的式子: n = (n - 1 % mod + mod) % mod +1 这里先减一,模上mod再加一,这样如果是整除mod的话先减一模上之后就变成mod-1,最后+1就变成mod了 这里模mod的方法是先模mod再加mod再模mod,这是常用的做法,目的是为了使得模的结过为正数,而不是负数.
Problem A A. Jzzhu and Children time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the chi
题目大意:给定 \(a,b,c\),求线性同余方程 \(ax+by=c\) 的最小正整数解. 题解:首先判断方程是否有解,若 c 不能整出 a 与 b 的最大公约数,则无解.若有解,则利用扩展欧几里得算法先求出 \(ax'+by'=gcd(a,b)\) 的一组解,再根据倍数进行缩放即可得到原不定方程的一组解.求最小正整数解可以根据公式 \((x\%mod+mod)\%mod\) 得出,原因如下:C++ 负数取模为截断机制,即:不会向下取整,直接进行截断.因此,若 x 为负数,则取模之后会变成绝对
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 2858 Accepted Submission(s): 1168 Problem Description In mathematics, a subsequence is a sequence that can be derived f
Description In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 = 1; F2 = 1; Fn = Fn - 1 + Fn - 2 (n > 2). DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of n integers:
B解题报告 算是规律题吧,,,x y z -x -y -z 注意的是假设数是小于0,要先对负数求模再加模再求模,不能直接加mod,可能还是负数 给我的戳代码跪了,,. #include <iostream> #include <cstring> #include <cstdio> using namespace std; long long x,y,z; long long n; int main() { cin>>x>>y; cin>&g
/* cf369E. ZS and The Birthday Paradox http://codeforces.com/contest/711/problem/E 抽屉原理+快速幂+逆元+勒让德定理+费马小定理+欧拉定理+数论 题解:https://amoshyc.github.io/ojsolution-build/cf/cf369/pe.html 坑点: 1.long long 类型的常量一定要加LL,否则1<<n只在int范围内 2.带模的题目,最后一定要判断是否答案为负,答案为负数要