current position:Home>Module product and problem solution of Luogu p2260 [Tsinghua training 2012]
Module product and problem solution of Luogu p2260 [Tsinghua training 2012]
2022-05-15 07:27:16【q779】
Luogu P2260 [ Tsinghua training 2012] Modular product sum Answer key
Topic link :P2260 [ Tsinghua training 2012] Modular product sum
The question :
seek
( ∑ i = 1 n ∑ j = 1 m ( n m o d i ) × ( m m o d j ) , i ≠ j ) m o d 19940417 \left(\sum_{i=1}^{n}\sum_{j=1}^{m}(n\bmod i)\times(m\bmod j),i\ne j \right) \mod 19940417 (i=1∑nj=1∑m(nmodi)×(mmodj),i=j)mod19940417
According to the principle of inclusion and exclusion
∑ i = 1 n ∑ j = 1 m ( n m o d i ) × ( m m o d j ) , i ≠ j = ∑ i = 1 n ∑ j = 1 m ( n m o d i ) × ( m m o d j ) − ∑ i = 1 n ( n m o d i ) × ( m m o d i ) \sum_{i=1}^{n}\sum_{j=1}^{m}(n\bmod i)\times(m\bmod j),i\ne j \\= \sum_{i=1}^{n}\sum_{j=1}^{m}(n\bmod i)\times(m\bmod j) - \sum_{i=1}^{n}(n\bmod i)\times(m\bmod i) i=1∑nj=1∑m(nmodi)×(mmodj),i=j=i=1∑nj=1∑m(nmodi)×(mmodj)−i=1∑n(nmodi)×(mmodi)
Then push the persimmon
∑ i = 1 n ∑ j = 1 m ( n m o d i ) × ( m m o d j ) − ∑ i = 1 n ( n m o d i ) × ( m m o d i ) = ∑ i = 1 n ( n − i ⌊ n i ⌋ ) × ∑ j = 1 m ( m − j ⌊ m j ⌋ ) − ∑ i = 1 n ( n − i ⌊ n i ⌋ ) × ( m − i ⌊ m i ⌋ ) = ( n 2 − ∑ i = 1 n i ⌊ n i ⌋ ) × ( m 2 − ∑ i = 1 m i ⌊ m i ⌋ ) − ∑ i = 1 n ( n m − m i ⌊ n i ⌋ − n i ⌊ m i ⌋ + i 2 ⌊ n i ⌋ ⌊ m i ⌋ ) = ( n 2 − ∑ i = 1 n i ⌊ n i ⌋ ) × ( m 2 − ∑ i = 1 m i ⌊ m i ⌋ ) − n 2 m + ∑ i = 1 n ( m i ⌊ n i ⌋ + n i ⌊ m i ⌋ − i 2 ⌊ n i ⌋ ⌊ m i ⌋ ) \begin{aligned} &\sum_{i=1}^{n}\sum_{j=1}^{m}(n\bmod i)\times(m\bmod j) - \sum_{i=1}^{n}(n\bmod i)\times(m\bmod i) \\&=\sum_{i=1}^{n}\left(n-i\left\lfloor{\dfrac{n}{i}}\right\rfloor\right)\times\sum_{j=1}^{m}\left(m-j\left\lfloor{\dfrac{m}{j}}\right\rfloor\right) - \sum_{i=1}^{n}\left(n-i\left\lfloor{\dfrac{n}{i}}\right\rfloor\right)\times\left(m-i\left\lfloor{\dfrac{m}{i}}\right\rfloor\right) \\&=\left(n^2-\sum_{i=1}^{n}i\left\lfloor{\dfrac{n}{i}}\right\rfloor\right)\times\left(m^2-\sum_{i=1}^{m}i\left\lfloor{\dfrac{m}{i}}\right\rfloor\right)-\sum_{i=1}^{n}\left(nm-mi\left\lfloor{\dfrac{n}{i}}\right\rfloor-ni\left\lfloor{\dfrac{m}{i}}\right\rfloor+i^2\left\lfloor{\dfrac{n}{i}}\right\rfloor\left\lfloor{\dfrac{m}{i}}\right\rfloor\right) \\&=\left(n^2-\sum_{i=1}^{n}i\left\lfloor{\dfrac{n}{i}}\right\rfloor\right)\times\left(m^2-\sum_{i=1}^{m}i\left\lfloor{\dfrac{m}{i}}\right\rfloor\right)-n^2m+\sum_{i=1}^{n}\left(mi\left\lfloor{\dfrac{n}{i}}\right\rfloor+ni\left\lfloor{\dfrac{m}{i}}\right\rfloor-i^2\left\lfloor{\dfrac{n}{i}}\right\rfloor\left\lfloor{\dfrac{m}{i}}\right\rfloor\right) \end{aligned} i=1∑nj=1∑m(nmodi)×(mmodj)−i=1∑n(nmodi)×(mmodi)=i=1∑n(n−i⌊in⌋)×j=1∑m(m−j⌊jm⌋)−i=1∑n(n−i⌊in⌋)×(m−i⌊im⌋)=(n2−i=1∑ni⌊in⌋)×(m2−i=1∑mi⌊im⌋)−i=1∑n(nm−mi⌊in⌋−ni⌊im⌋+i2⌊in⌋⌊im⌋)=(n2−i=1∑ni⌊in⌋)×(m2−i=1∑mi⌊im⌋)−n2m+i=1∑n(mi⌊in⌋+ni⌊im⌋−i2⌊in⌋⌊im⌋)
There is a small formula , There's no proof ( flee
∑ i = 1 n i 2 = n ( n + 1 ) ( 2 n + 1 ) 6 \sum_{i=1}^{n}i^2 = \dfrac{n(n+1)(2n+1)}{6} i=1∑ni2=6n(n+1)(2n+1)
Then there's no difficulty here
Consider number theory blocking
The code is as follows
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int p=19940417;
const int inv2=9970209;
const int inv6=3323403;
#define sum1(x) ((x)%p*(x+1)%p*inv2%p)
#define sum2(x) ((x)%p*(x+1)%p*(2*(x)%p+1)%p*inv6%p)
int solve(int x)
{
int res=x%p*x%p;
for(int l=1,r; l<=x; l=r+1)
{
r=x/(x/l);
res=(res-(sum1(r)-sum1(l-1))%p*(x/l)%p)%p;
}
return res;
}
int n,m,a,b,c,ans;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> m;
if(n>m)swap(n,m);
ans=(solve(n)*solve(m)%p-n%p*n%p*m%p)%p;
for(int l=1,r; l<=n; l=r+1)
{
r=min(n/(n/l),m/(m/l));
a=(a+(sum1(r)-sum1(l-1))%p*m%p*(n/l)%p)%p;
b=(b+(sum1(r)-sum1(l-1))%p*n%p*(m/l)%p)%p;
c=(c+(sum2(r)-sum2(l-1))%p*(n/l)%p*(m/l)%p)%p;
}ans=((ans+a+b-c)%p+p)%p;
cout << ans << endl;
return 0;
}
Reprint please explain the source
copyright notice
author[q779],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102141448432.html
The sidebar is recommended
- 2019 CCPC Qinhuangdao station question D (simple mathematics) gym - 102361d decimal
- Cubic difference derivation
- Number theory -- p2260 [Tsinghua training] modular product sum
- Number theory -- division and blocking
- Time complexity analysis of divide and conquer strategy (III) - solving recursive equation by main method
- Time complexity analysis of divide and conquer strategy (II) - solving recursive equations by recursive tree method
- Aslfeat (CVPR 2020) feature point detection paper notes
- PTA Fibonacci sequence (I)
- 2018 ICPC Xuzhou online game D. easy math (Mobius inversion, Du jiaoshai, memory search)
- Least mean squares regression (II)
guess what you like
Basic number theory -- division and congruence
Basic number theory -- Cartland number
[digital signal processing] sequence classification (unilateral sequence and bilateral sequence | finite sequence and infinite sequence | stable sequence and unstable sequence)
Time complexity analysis of quick sort
[digital signal processing] linear time invariant system LTI (judge whether a system is a "linear" system | case 4)
[digital signal processing] relationship between "input" and "output" of linear time invariant system LTI (linear convolution starting point theorem | left sequence concept | reasoning)
[digital signal processing] relationship between "input" and "output" of linear time invariant system LTI (linear convolution calculation method list | linear convolution calculation case 1 | directly calculate convolution according to the definition of l
[digital signal processing] relationship between "input" and "output" of linear time invariant system LTI (derivation process of linear convolution starting point theorem)
Csp202112-1: sequence query solution
[divide and divide] [prefix and] [DP] D. up the strip (simple version + normal version)
Random recommended
- Big O, how do you calculate / approximate it?
- Mobius inversion & binomial inversion
- [digital signal processing] linear constant coefficient difference equation (determine whether the system is a "linear time invariant system" according to "linear constant coefficient difference equation" and "boundary conditions" | prove it by recursive
- [digital signal processing] linear constant coefficient difference equation (determine whether the system is a "linear time invariant system" according to "linear constant coefficient difference equation" and "boundary conditions". Case 2 | modify the bou
- [digital signal processing] correlation function (example of autocorrelation function)
- [digital signal processing] correlation function application (correlation function application scenario | signal detection principle in noise)
- Codeforces round 772 (Div. 2) C. differential sorting
- Asymptotic notation (supplementary understanding)
- Calculating the time complexity of merging and sorting
- [digital signal processing] sequential Fourier transform (examples of Fourier transform | Fourier transform | amplitude frequency characteristics of Fourier transform | phase frequency characteristics of Fourier transform)
- Regular replace the same row (after sorting)
- [digital signal processing] summary of Fourier transform of basic sequence (unit pulse sequence) δ (n) | {1} sequence | e ^ J ω N sequence | cos ω N sequence | sin ω N sequence | a ^ nu (n) | rectangular window function)***
- [digital signal processing] sequence Fourier transform (Fourier transform of basic sequence | Fourier transform of a ^ nu (n))
- LeetCode 798. Minimum rotation with the highest score
- sequence inequality
- Realize factorial formula and permutation and combination formula
- [cf1627b] not sitting
- Let me summon the Buddha to bless you without bugs
- Euler function + Dirichlet convolution + Mobius function + Mobius inversion + division and blocking + Du Jiao sieve
- Mathematical analysis and problem solving ideas
- 104. Warehouse location
- JSON array flat structure conversion tree menu nested structure
- JSON array flat structure conversion tree menu nested structure
- Artillery position (shape pressure DP)
- Convergence method of infinite series (II) series with constant term
- P5303 [gxoi / gzoi2019] forced death obsessive-compulsive disorder (fiboracci, matrix multiplication)
- [advanced mathematics notes] Wallis integral formula
- Notes on Advanced Mathematics: Prelude
- Staggered formula and line split plane formula
- Luogu p5333 / bzoj5528 / loj3102 [jsoi2019] neural network tree DP + generation function
- Number of factors
- 20.3 GCD and LCM - [maximum and minimum common multiples]
- Yanghui triangle programming printing has the following form of Yanghui triangle (its feature is that the left and right sides are all 1. From the second line, each number in the middle is the sum of two adjacent numbers in the previous line), in which th
- 7-5 square array cyclic right shift (20 points)
- Why is the merge sort time complexity nlgn
- Euler function + Dirichlet convolution + Mobius function + Mobius inversion + division and blocking + Du Jiao sieve
- C language goods placement
- Window function design FIR filter