Problem Description
Avin is studying how to synthesize data. Given an integer n, he constructs an interval using the following method: he first generates a integer r between 1 and n (both inclusive) uniform-randomly, and then generates another integer l between 1 and r (both inclusive) uniform-randomly. The interval [l, r] is then constructed. Avin has constructed two intervals using the method above. He asks you what the probability that two intervals intersect is. You should print p* q(−1)(MOD 1, 000, 000, 007), while pq denoting the probability.
 

求逆元的几种方法:https://blog.csdn.net/xiaoming_p/article/details/79644386

Input
Just one line contains the number n (1 ≤ n ≤ 1, 000, 000).
 
Output
Print the answer.
 
Sample Input
1
2
 
Sample Output
1
750000006
 
规律:(n+1)*n/2/(n*n)
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
const long long mod=1e9+;
typedef long long ll;
using namespace std; ll ksm(ll x,ll y)
{
ll ans=;
while(y)
{
if(y&)
ans=ans*x%mod;
y>>=;
x=x*x%mod;
}
return ans;
}
int main()
{
ll n;
while(cin>>n)
{
ll p=(n+)*n/;
ll q=n*n;
printf("%lld\n",(p*ksm(q,mod-))%mod);
}
return ;
}
 
 

Rng(求逆元)的更多相关文章

  1. # 江西CCPC省赛-Rng(概率+逆元)

    江西CCPC省赛-Rng(概率+逆元) 题意: 给出一个n,在[1,n]之间选一个R1,在[1,R1]之间选一个L1,得到区间[L1,R1],同理获取区间[L2,R2],问两个区间相交的概率对1e9+ ...

  2. CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)

    Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...

  3. 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数

    1.gcd int gcd(int a,int b){ return b?gcd(b,a%b):a; } 2.扩展gcd )extend great common divisor ll exgcd(l ...

  4. 【BZOJ-4522】密钥破解 数论 + 模拟 ( Pollard_Rho分解 + Exgcd求逆元 + 快速幂 + 快速乘)

    4522: [Cqoi2016]密钥破解 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 290  Solved: 148[Submit][Status ...

  5. hdu 1576 求逆元

    题意:给出n=A mod 9973和B,求(A/B) mod 9973 昨天用扩展欧几里得做过这题,其实用逆元也可以做. 逆元的定义:例如a*b≡1 (mod m),则b就是a关于m的逆元. 求逆元方 ...

  6. HDU4869:Turn the pokers(快速幂求逆元+组合数)

    题意: 给出n次翻转和m张牌,牌相同且一开始背面向上,输入n个数xi,表示xi张牌翻转,问最后得到的牌的情况的总数. 思路: 首先我们可以假设一开始牌背面状态为0,正面则为1,最后即是求ΣC(m,k) ...

  7. ZOJ 3609 求逆元

    Modular Inverse Time Limit: 2 Seconds      Memory Limit: 65536 KB The modular modular multiplicative ...

  8. codeforces 492E. Vanya and Field(exgcd求逆元)

    题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...

  9. 51NOD 1258 序列求和 V4 [任意模数fft 多项式求逆元 伯努利数]

    1258 序列求和 V4 题意:求\(S_m(n) = \sum_{i=1}^n i^m \mod 10^9+7\),多组数据,\(T \le 500, n \le 10^{18}, k \le 50 ...

随机推荐

  1. python2.2 elif多条件判断

    #案例:存款大于100万,买宝马:大于50万买丰田:大于20万买二手车:小于20万自行车! cunkuan=60#elif多条件判断,else:不满足elif执行其他命令if cunkuan>1 ...

  2. qt事件过滤器的使用(可以用于控制屏幕背光等)

    在嵌入式qt项目中,有时并不需求屏幕一直亮着,需要一段时间不操作时,将屏幕背光关掉,以达到节能的目的: 在qt项目中,可以通过重写事件过滤器来实现屏幕操作的检测,加上定时器的时间控制,可以实现指定时间 ...

  3. C#LeetCode刷题之#441-排列硬币(Arranging Coins)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3995 访问. 你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状 ...

  4. vue scss 样式穿透

    使用2个style的方式不够优雅,可以使用下面方式做样式穿透 .normal-field /deep/ .el-form-item { margin-bottom: 0px; } .normal-fi ...

  5. LeetCode 90 | 经典递归问题,求出所有不重复的子集II

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题第56篇文章,我们一起来看看LeetCode第90题,子集II(Subsets II). 这题的官方难度是Medi ...

  6. Java中的策略模式,完成一个简单地购物车,两种付款策略实例教程

    策略模式是一种行为模式.用于某一个具体的项目有多个可供选择的算法策略,客户端在其运行时根据不同需求决定使用某一具体算法策略. 策略模式也被称作政策模式.实现过程为,首先定义不同的算法策略,然后客户端把 ...

  7. SpringBoot ---yml 整合 Druid(1.1.23) 数据源

    SpringBoot ---yml 整合 Druid(1.1.23) 数据源 搜了一下,网络上有在配置类写 @Bean 配置的,也有 yml 配置的. 笔者尝试过用配置类配置 @Bean 的方法,结果 ...

  8. 【算法•日更•第二期】查找算法:三分VS二分

    ▎前言:函数 如果你已经上过初二的数学课了,那么你十有八九会被函数折磨到吐血,这是一种中考压轴题类的题目,往往分类讨论到你恶心.不过没学过也不打紧,现场讲解一下: ☞『数学中的函数』 一般地,如果在一 ...

  9. vue watch 和 computed 区别与使用

    目录 computed 和 watch 的说明 与 区别 computed 计算属性说明: watch 监听属性说明: watch 和 computed 的区别是: 使用 参考官方文档 compute ...

  10. CSS动画实例:太极图在旋转

    利用CSS可以构造出图形,然后可以对构造的图形添加动画效果.下面我们通过旋转的太极图.放大的五角星.跳“双人舞”的弯月等实例来体会纯CSS实现动画的方法. 1.旋转的太极图 设页面中有<div ...