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. 为什么需要将网站封装为app?

      网站封装为app是一种宝贵的资源,为客户提供稳定的平台,一个网站也是一个有效的工具,用于企业与其客户之间的通信.企业网站用户可以通过他们的笔记本电脑,台式机,平板电脑,智能手机以及带有浏览器设备的 ...

  2. DataGrip,一款数据库客户端工具,IDEA的兄弟是真香!

    DataGrip 是一款数据库管理客户端工具,方便的连接到数据库服务器,执行sql语句.创建表.创建索引以及导出数据等. DataGrip 支持几乎所有主流的关系数据库产品,如 DB2.Derby.H ...

  3. 苹果挖矿恶意程序处理(OSX/CoinMiner.X)

    背景 近期通过流量告警发现多起外连矿池的告警,均外连至43.249.204.231 威胁情报信息如下: 系统表象 1.通过ps -ef|grep osascript发现在/library/Launch ...

  4. “随手记”开发记录day20

    练习软件的展示,尽量将软件全方面的展示给大众,希望不要像上次一样有许多遗漏的地方,让其他团队以为我们的软件没有完善的功能.

  5. Python实现进度条和时间预估的示例代码

    一.前言 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识.那么针对这三类人,我给大家 ...

  6. 静态集成腾讯TBS X5内核WebView,从微信提取新版30M浏览器内核打包进apk

    目录 前情提要 第一步:下载老版本SDK得到jar 获取SDK 集成SDK 步骤二.下载提取最新TBS X5内核 方法1:从微信中提取 方法2:App内内访问tbs调试页安装新内核 步骤三.集成内核到 ...

  7. layui 事件监听触发

    1:监听select 改变 <!-- 不用form 用div也可以 --> <form class="layui-form"> <div class= ...

  8. JavaScript promise基础示例

    const { info } = console // cooking function cook() { info('[COOKING] start cooking.') const p = new ...

  9. Linux Centos 下安装npm 实测可用

    转载地址 https://blog.csdn.net/u012129607/article/details/60966045 1.root 登录linux 2.没有目录就自己创建一个 cd /usr/ ...

  10. MongoDB学习1:认识文档数据库MongoDB

    1. 关于MongoDB 什么是MongoDB 一个以JSON为数据模型的文档数据库 为什么叫文档数据库 文档来自于"JSON Document",并非我们一般理解的pdf,wor ...