当前位置:网站首页>AcWing 1294. Cherry Blossom explanation
AcWing 1294. Cherry Blossom explanation
2022-07-06 11:16:00 【Octopus loving monster】
AcWing 1294. Cherry blossoms Answer key
Title Description
Given an integer n n n , Find how many positive integer pairs ( x , y ) (x,y) (x,y) Satisfy 1 x + 1 y = 1 n ! \dfrac{1}{x}+\dfrac{1}{y}=\dfrac{1}{n!} x1+y1=n!1
Input format :
An integer n n n
Output format :
An integer , Indicates the number of pairs that meet the conditions
The answer is right 1 0 9 + 7 10^9+7 109+7 modulus
Data range
1 ≤ n ≤ 1 0 6 1\le n \le 10^6 1≤n≤106
Answer key
Look at the formula , Easy to launch x > n ! x > n! x>n! y > n ! y >n! y>n!
Two unknowns x , y x,y x,y, Knowing one of them, you can launch another
So we might as well set y = n ! + k y=n!+k y=n!+k
The transformed formula is
1 x + 1 n ! + k = 1 n ! \dfrac{1}{x}+\dfrac{1}{n!+k}=\dfrac{1}{n!} x1+n!+k1=n!1
Divide the formula on both sides to get n ! ( n ! + k ) + ( n ! ) x = x ( n ! + k ) n!(n!+k)+(n!)x=x(n!+k) n!(n!+k)+(n!)x=x(n!+k)
Change can get
x = n ! ( n ! + k ) k = ( n ! ) 2 k + n ! x=\dfrac{n!(n!+k)}{k}=\dfrac{(n!)^2}{k}+n! x=kn!(n!+k)=k(n!)2+n!
because x To satisfy the property of positive integers , So the problem turns into k The value of needs to become ( n ! ) 2 (n!)^2 (n!)2 The divisor of
The problem became Find the divisor of a number
To find the divisor, you can use Basic theorem of arithmetic
The basic theorem of arithmetic is as follows
Any positive integer can be uniquely determined by its prime factor ( among p i p_i pi Is its qualitative factor )
x = p 1 α 1 ⋅ p 2 α 2 ⋅ p 3 α 3 … ⋅ p n α n x=p_1^{\alpha_1} · p_2^{\alpha_2}·p_3^{\alpha_3}\dots·p_n^{\alpha_n} x=p1α1⋅p2α2⋅p3α3…⋅pnαn
According to the full arrangement formula, the number of factors is
( α 1 + 1 ) ⋅ ( α 2 + 1 ) ⋅ ( α 2 + 1 ) ⋅ ( α 2 + 1 ) (\alpha_1+1)·(\alpha_2+1)·(\alpha_2+1)·(\alpha_2+1) (α1+1)⋅(α2+1)⋅(α2+1)⋅(α2+1)
The problem becomes a solution ( n ! ) 2 (n!)^2 (n!)2 The prime factor of and the order of each prime factor
We can ask for ( n ! ) (n!) (n!) And the order of each prime factor, then multiply the order 2 You can get there ( n ! ) 2 (n!)^2 (n!)2 Solution
How to find ( n ! ) (n!) (n!) For the quality factor and the order of the quality factor, please refer to my other blog
AcWing 197. Factorial decomposition Answer key
Get ( n ! ) (n!) (n!) Multiply the order of the prime factor by 2, Finally, by using the calculation formula of the number of factors, we can get k All values of
For each of these k Each value has a x The value corresponds to , Then all the final values are the number of positive integer pairs
Complete code
import java.io.*;
import java.util.*;
public class Main {
static int n;
static final int N=1000010;
static final long MOD=1000000007;
static int[] Primes =new int[N];
static boolean[] isPrime =new boolean[N];
static int cnt=0;
static long ans=1;
public static void init(int n)// Linear sieve
{
Arrays.fill(isPrime,true);
for(int i=2;i<=n;i++) {
if (isPrime[i])
Primes[cnt++] = i;
for(int j=0;j<cnt;j++)
{
int p=Primes[j];
if(i*p>n)
break;
isPrime[i*p]=false;
if(i%p==0)
{
break;
}
}
}
}
public static void main(String[] agrs) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(reader.readLine());
init(n);
for(int i=0;i<cnt;i++)// Decomposing the prime factor
{
int tmp=n;
int p=Primes[i];
long res=0;
while(tmp>0)
{
res+=tmp/p;
tmp/=p;
}
res*=2;// The order of the prime factor converted to square
ans=(ans%MOD)*((res+1)%MOD);// Factor calculation formula
ans%=MOD;
}
System.out.println(ans);
}
}
边栏推荐
- Learning question 1:127.0.0.1 refused our visit
- One click extraction of tables in PDF
- AcWing 179.阶乘分解 题解
- 基于apache-jena的知识问答
- Asp access Shaoxing tourism graduation design website
- Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
- npm一个错误 npm ERR code ENOENT npm ERR syscall open
- Some problems in the development of unity3d upgraded 2020 VR
- 1. Mx6u learning notes (VII): bare metal development (4) -- master frequency and clock configuration
- Attention apply personal understanding to images
猜你喜欢
Swagger、Yapi接口管理服务_SE
Django running error: error loading mysqldb module solution
Use dapr to shorten software development cycle and improve production efficiency
Postman environment variable settings
Idea import / export settings file
Rhcsa certification exam exercise (configured on the first host)
QT creator design user interface
Install mongdb tutorial and redis tutorial under Windows
Install mysql5.5 and mysql8.0 under windows at the same time
MySQL主从复制、读写分离
随机推荐
SSM整合笔记通俗易懂版
Did you forget to register or load this tag
FRP intranet penetration
MySQL主從複制、讀寫分離
机器学习--人口普查数据分析
Solution: log4j:warn please initialize the log4j system properly
导入 SQL 时出现 Invalid default value for ‘create_time‘ 报错解决方法
MySQL master-slave replication, read-write separation
A brief introduction to the microservice technology stack, the introduction and use of Eureka and ribbon
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
++Implementation of I and i++
When you open the browser, you will also open mango TV, Tiktok and other websites outside the home page
项目实战-后台员工信息管理(增删改查登录与退出)
安全测试涉及的测试对象
Did you forget to register or load this tag 报错解决方法
AcWing 1294.樱花 题解
自动机器学习框架介绍与使用(flaml、h2o)
Use dapr to shorten software development cycle and improve production efficiency
Unable to call numpy in pycharm, with an error modulenotfounderror: no module named 'numpy‘
Software testing and quality learning notes 3 -- white box testing