题意 求满足$na^n\equiv b \pmod p$的$n$的个数 因为$n \mod p ​$循环节为$p​$,$a^n\mod p​$循环节为$p-1​$,所以$na^n \mod p​$循环节为$p(p-1)​$ 假设$n \mod p \equiv i,a^n\mod p\equiv a^j$ , 那么$n%p \times a^n%p\equiv b \pmod p$,得到$i \times a^j \equiv b \pmod p$,列同余方程$i \equiv b*a^{-j}…
Description 题面 \(n*a^n≡b (\mod P),1<=n<=x\) Solution 令 \(n=(P-1)*i+j\) \([(P-1)*i+j]*a^{[(P-1)*i+j]} ≡b (\mod P)\) 由费马小定理 \([(P-1)*i+j]*a^j ≡b (\mod P)\) \(i ≡j-\frac{b}{a^{j}} (\mod P)\) 然后就可以枚举\(j\),算\(i\)的取值种数了 利用 \(i\) 的限制:\(i*(P-1)+j<=x\),可以…
cf 460 E. Congruence Equation 数学题 题意: 给出一个x 计算<=x的满足下列的条件正整数n的个数 \(p是素数,2 ≤ p ≤ 10^{6} + 3, 1 ≤ a, b < p, 1 ≤ x ≤ 10^{12}\) 思路: 题目中存在两个循环节 \(n % p\) 和 \(a ^ n % p\), 循环节分别为\(p,p-1\) 我们枚举\(i = n\ (mod)\ (p - 1)\) 可以得到两个方程 \[ n\ \equiv\ i\ mod\ (p-1)…
原文链接http://www.cnblogs.com/zhouzhendong/p/8397685.html 2018-02-01 $A$ 题意概括 你要买$m$斤水果,现在有$n$个超市让你选择. 每个超市的水果价格是固定的.第$i$个超市的水果价格用两个整数$a_i和b_i$来表示.含义是$a_i$元可以买$b_i$斤. 问你买$m$斤水果最少花费多少钱. 题解 直接枚举超市,判断最少的花费就可以了. 代码 #include <cstring> #include <cstdio>…
E. Congruence Equation time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Given an integer x. Your task is to find out how many positive integers n (1 ≤ n ≤ x) satisfy where a, b, p are all k…
Supermarket 找最便宜的就行 Solution Perfect Number 暴力做 Solution Seat Arrangement 注意当k=1时,横着和竖着是同一种方案 Solution Substring dp[i][j]表示在节点i结束,字母j最多有多少个,按拓扑排序的顺序计算 Solution Congruence Equation Solution A Game With Numbers 跟SG游戏解决思路差不多 Solution…
http://poj.org/problem?id=2891 题意就是孙子算经里那个定理的基础描述不过换了数字和约束条件的个数…… https://blog.csdn.net/HownoneHe/article/details/52186204 这个博客提供了互质情况下的代码以及由此递推出的(另一个版本的)非互质情况下的代码. 假如给出m[n],a[n]分别代表要求的除数和余数: 互质情况下: ( 做n次 ) 对不包含m[i]的所有m求积 ( 互质的数的最小公倍数 ) , exgcd求出来逆元后…
题目链接: http://codeforces.com/problemset/problem/919/E 题意: 让你求满足 \(na^n\equiv b \pmod p\) 的 \(n\) 的个数. \(2 ≤ p ≤ 10^{6} + 3, 1 ≤ a, b < p, 1 ≤ x ≤ 10^{12}\). 题解: 因为: $n \mod p $的循环节是 \(p\) \(a^{n} \mod p\)的循环节是 \(p-1\).(费马小定理) 所以: \(na^n \mod p​\)的循环节为…
Description Karen just got home from the supermarket, and is getting ready to go to sleep. After taking a shower and changing into her pajamas, she looked at her shelf and saw an album. Curious, she opened it and saw a trading card collection. She re…
Problem A:题目传送门 题目大意:给你N家店,每家店有不同的价格卖苹果,ai元bi斤,那么这家的苹果就是ai/bi元一斤,你要买M斤,问最少花多少元. 题解:贪心,找最小的ai/bi. #include <cstdio> using namespace std; double minn=2e9,x,y,M; int N; int read() { '); +c-'; return x; } inline double min(double x,double y){return x<…