codeforces 711E 数学

计算1-(2^n-1)*...*(2^n-(k-1))/(2^n(k-1)).

先算公约数,可以看出公约数只能是2的n次幂,求每个分子和2的n次幂的最大公约数,因为gcd(a,b)=gcd(b-a,a),所以直接求2^n和(k-1)!的公约数,然后同除就行。这里有勒让德定理:在正数n!的素因子标准分解式中,素数p的指数记作,则。然后就能算出有多少2的约数,一除就行。

最后如果是大于最多的天数,就直接输出1。

时间: 2024-08-27 22:30:29

codeforces 711E 数学的相关文章

CodeForces 776E 数学规律,欧拉

CodeForces 776E 题意:定义f(n)为(x,y)的对数,x和y要满足 x>0, y>0, x+y=n, x与y互质. 定义g(n)为f(x1)+f(x2)+......+f(xk),xi为n的因子. 再定义Fk(n)为     给定n和k,求Fk(n). tags: 好假的题..推理或者找规律,f(n)=phi(n), g(n)=n... #include<bits/stdc++.h> using namespace std; #pragma comment(link

Codeforces 711E ZS and The Birthday Paradox(乘法逆元)

[题目链接] http://codeforces.com/problemset/problem/711/E [题目大意] 假设一年有2^n天,问k个小朋友中有两个小朋友生日相同的概率. 假设该概率约分后为 p / q ,输出p , q对1000003取模的解. [题解] 当k比天数要大时是肯定成立的,否则答案为1-A(2n,k) / (2n)k, 考虑A(2n,k)=2n*(2n-1)*……*(2n-k+1),所以分子和分母的最大公约数是2的幂次,暴力计算分子分母,以及计算最大公约数的逆元,就可

codeforces 711E. ZS and The Birthday Paradox 概率

已知一年365天找23个人有2个人在同一天生日的概率 > 50% 给出n,k ,表示现在一年有2^n天,找k个人,有2个人在同一天生日的概率,求出来的概率是a/b形式,化到最简形式,由于a,b可能非常大,对a,b分别%(10^6+3) 注意,这道题是先化到最简,再分别取模 首先,特判 k > 2^n 时,a = 1,b = 1 没有2个人同一天生日的概率为: 2^n * (2^n - 1) * ... * (2^n - k + 1) / 2^(nk) 所以a,b化简之前分别是: a = 2nk

Codeforces 300E(数学)

题意:给定k个数字,求最小的正整数n,使得“n的阶乘”是“这k个数字的阶乘的积”的倍数.1<=k<=1e6,数字ai满足1<=ai<=1e7 分析:如果我们能对着k个数字的阶乘的结果分解质因数,那么就可以根据每个质因数的指数来二分最后的答案 问题的关键就是如何分解a1!a2!a3!a4!..... 先可以预处理出1..MAX每个数在式子中出现了多少次(对于ai,也就是1~ai中间所有数字出现次数+1),这可以用差分做 我们知道了cnt[1..MAX]后,接下来就是考虑分解了 我们从

CodeForces 484B 数学 Maximum Value

很有趣的一道题,题解戳这. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 const int maxn = 200000 + 10; 8 const int maxm = 1000000 + 10; 9 10 int a[maxn], f[maxm]; 11 12 int main

CodeForces 454C——数学——Little Pony and Expected Maximum

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has m faces: the firs

Codeforces 1114E(数学+随机算法)

题面 传送门 分析 通过二分答案,我们显然可以求出数组中最大的数,即等差数列的末项 接着随机取一些数组中的数,对他们两两做差,把得到的差取gcd即为公差 例a={1,5,9,13},我们随机取了1 9 13,两两的差为8,4,12,取gcd为4 已知末项和公差即可求出首项 可以证明错误的概率< \(1.86185\times10?^{-9}\) 具体证明我也不懂,可以看cf官方题解,需要用到莫比乌斯反演 注意生成随机数时不能直接用rand(),因为rand()的返回值<32768,而n很可能&

Codeforces Beta Round #85 (Div. 1 Only) C (状态压缩或是数学?)

C. Petya and Spiders Little Petya loves training spiders. Petya has a board n × m in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform it

codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)

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: a1, a2, ...,