当前位置:网站首页>Interval product of zhinai sauce (prefix product + inverse element)
Interval product of zhinai sauce (prefix product + inverse element)
2022-07-03 20:24:00 【MangataTS】
Topic link
https://ac.nowcoder.com/acm/contest/19483/A
Topic
Ideas
We require that the product of intervals be 1 e 9 + 7 1e9+7 1e9+7 Submodule , Then this is a template of prefix product , And prefixes and similar , We just need to initialize p r e [ 0 ] pre[0] pre[0] by 1, Then when we do a division, we can't divide directly , Because there will be accuracy problems , So here we need to use Inverse element To help us with division
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
const int N = 1e5+10;
ll pre[N],a[N];
int n,m;
ll qpow(ll a,ll b) {
ll ans =1;
while(b) {
if(b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
ll inv(ll a) {
return qpow(a,mod-2);
}
int main()
{
pre[0] = 1;
scanf("%d%d",&n,&m);
for(int i = 1;i <= n; ++i) {
scanf("%lld",&a[i]);
pre[i] = pre[i - 1] * a[i] % mod;
}
int l,r;
while(m--) {
scanf("%d %d",&l, &r);
printf("%lld\n",pre[r] * inv(pre[l-1]) % mod);
}
return 0;
}
边栏推荐
- 2.2 integer
- Explore the internal mechanism of modern browsers (I) (original translation)
- P5.js development - setting
- Instructions for common methods of regular expressions
- Shortest path problem of graph theory (acwing template)
- 2.6 formula calculation
- It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET
- Gym welcomes the first complete environmental document, which makes it easier to get started with intensive learning!
- Parental delegation mechanism
- Task of gradle learning
猜你喜欢
thrift go
Wargames study notes -- Leviathan
2.7 format output of values
In 2021, the global revenue of syphilis rapid detection kits was about US $608.1 million, and it is expected to reach US $712.9 million in 2028
Explore the internal mechanism of modern browsers (I) (original translation)
HCIA-USG Security Policy
Upgrade PIP and install Libraries
Task of gradle learning
Basic knowledge of dictionaries and collections
Test changes in Devops mode -- learning and thinking
随机推荐
MySQL learning notes - single table query
The simplicity of laravel
2. Template syntax
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
Typora charges, WTF? Still need support
Cap and base theory
JMeter plug-in installation
What is the difference between a kill process and a close process- What are the differences between kill process and close process?
Change deepin to Alibaba image source
Example of peanut shell inner net penetration
Global and Chinese market of two in one notebook computers 2022-2028: Research Report on technology, participants, trends, market size and share
FPGA learning notes: vivado 2019.1 project creation
AI enhanced safety monitoring project [with detailed code]
Class loading process
4. Data splitting of Flink real-time project
[Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
Global and Chinese markets of active matrix LCD 2022-2028: Research Report on technology, participants, trends, market size and share
Promethus
Test access criteria
Plan for the first half of 2022 -- pass the PMP Exam