当前位置:网站首页>[day 29] given an integer, please find its factor number
[day 29] given an integer, please find its factor number
2022-07-03 01:16:00 【Stubble】
Learning Guide
order 、 Column Preface
This column opens , The purpose is to help everyone better master learning Java
, Especially some Java Learners'
It is difficult to find systematic algorithm learning materials on the Internet to help you get started with algorithms , At the same time, if you have any questions about the contents of the column, you can add my wechat at the end of the article to give you a one-to-one explanation .
But the most important thing is to think independently , For all the content of this column , Be able to fully master , Write the code completely by yourself , There must be no problem getting started with the algorithm .
The learning of algorithm must not be short of summary , Here I recommend that you can go to University algorithm community Punch in the learned knowledge , To consolidate and review .
The only way to learn algorithms well must be Topic sea strategy , Only by accumulating a lot of practice can you practice your skills . Any topic of the column I will start with 【 Title Description 】【 Their thinking 】【 Template code 】【 Code parsing 】 Wait for four plates to explain .
One 、【 Example 1】
1、 Title Description
Given an integer n ( 1 ≤ n ≤ 100000 ) n(1\le n \le100000) n(1≤n≤100000), Please find out the number of factors .
2、 Their thinking
- ( 1 ) (1) (1) We can think of the previous articles on judging prime numbers , Because the determination of prime number also depends on the factor number of a number , It was written at that time O ( n ) O(n) O(n) And a O ( n ) O(\sqrt n) O(n) How to do it .
3、 Template code
1.O(n) practice
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ans=0;
for (int i = 1; i <=n; i++) {
if (n%i==0) ans++;
}
System.out.println(ans);
}
}
2. Radical sign n practice
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int ans=0;
for (int i = 1; i <=n/i; i++) {
if (n%i==0){
if (i!=n/i) ans+=2;
else ans++;
}
}
System.out.println(ans);
}
}
3. Theorem of the number of approximations
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(getsum(n));
}
static int getsum(int n){
int ans=1;
for (int i = 2; i <=n/i; i++) {
if (n%i==0){
int a=0;
while (n%i==0){
a++;
n/=i;
}
ans*=(a+1);
}
}
if (n>1) ans*=2;
return ans;
}
}
4、 Code parsing
- ( 1 ) (1) (1) The first two methods are not mentioned here , In the 5 5 5 It is explained in the prime number determination of days , Let's focus on the theorem of approximate numbers .
- ( 2 ) (2) (2) For a greater than 1 1 1 The integer of n n n, Decomposable prime factor
n = ∏ i = 1 k p i a i = p 1 a 1 × p 2 a 2 × p 3 a 3 . . . . . . p k a k n=\prod_{i=1}^{k} p_i^{a^i}=p_1^{a^1}\times p_2^{a^2}\times p_3^{a^3}......p_k^{a^k} n=i=1∏kpiai=p1a1×p2a2×p3a3......pkak
be n n n The positive divisors of are f ( n ) = ∏ i = 1 k ( a i + 1 ) = ( a 1 + 1 ) ( a 2 + 1 ) . . . ( a k + 1 ) . f(n)=\prod_{i=1}^{k}(a_i+1)=(a_1+1)(a_2+1)...(a_k+1). f(n)=∏i=1k(ai+1)=(a1+1)(a2+1)...(ak+1).
among a 1 、 a 2 、 a 3 . . . a k a_1、a_2、a_3...a_k a1、a2、a3...ak yes p 1 、 p 2 、 p 3 、 . . . p k p_1、p_2、p_3、...p_k p1、p2、p3、...pk The index of . - ( 3 ) (3) (3) Theorem proving : about n n n, We have : n = p 1 a 1 × p 2 a 2 × p 3 a 3 . . . . . . p k a k n=p_1^{a^1}\times p_2^{a^2}\times p_3^{a^3}......p_k^{a^k} n=p1a1×p2a2×p3a3......pkak
about n n n Any divisor of d d d, Then there are d = p 1 β 1 × p 2 β 2 × p 3 β 3 . . . . . . p k β k d=p_1^{^\beta1}\times p_2^{\beta ^2}\times p_3^{\beta ^3}......p_k^{\beta^k} d=p1β1×p2β2×p3β3......pkβk, among ( 0 ≤ β i ≤ a i ) (0 \le \beta_i \leq a_i) (0≤βi≤ai), every last β i \beta_i βi The value of is in total ( a i + 1 ) individual (a_i+1) individual (ai+1) individual . Of each item β i \beta _i βi Different , Then the divisors are different . β 1 \beta _1 β1 The range is [ 0 , a 1 ] [0,a_1] [0,a1], β 2 \beta _2 β2 The range is [ 0 , a i ] [0,a_i] [0,ai], β k \beta _k βk The de value range of is [ 0 , a k ] [0,a_k] [0,ak]. - ( 4 ) (4) (4) According to the principle of multiplication , n n n The approximate number of f ( n ) = ( a 1 + 1 ) ( a 2 + 1 ) . . . ( a k + 1 ) f(n)=(a_1+1)(a_2+1)...(a_k+1) f(n)=(a1+1)(a2+1)...(ak+1)
3、 ... and 、 Recommendation column
Four 、 After-school exercises
Serial number | Topic link | Difficulty rating |
---|---|---|
1 | Ugly number | 2 |
边栏推荐
- Basic remote connection tool xshell
- Assets, vulnerabilities, threats and events of the four elements of safe operation
- 2022 cable crane driver examination registration and cable crane driver certificate examination
- MySQL foundation 07-dcl
- Understanding and distinguishing of some noun concepts in adjustment / filtering
- Cut point of undirected graph
- MySQL --- 数据库查询 - 条件查询
- 1696C. Fishingprince Plays With Array【思维题 + 中间状态 + 优化存储】
- 【爱死机】《吉巴罗》被忽略的细节
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
猜你喜欢
excel表格计算时间日期的差值,并转化为分钟数
【无标题】
Foundations of data science is free to download
leetcode:701. 二叉搜索树中的插入操作【bst的插入】
leetcode 2097 — 合法重新排列数对
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
无向图的割点
Excel removes the data after the decimal point and rounds the number
[AUTOSAR 11 communication related mechanism]
Excel if formula determines whether the two columns are the same
随机推荐
删除有序链表中重复的元素-II
[shutter] image component (cached_network_image network image caching plug-in)
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
2022 cable crane driver examination registration and cable crane driver certificate examination
关于Fibonacci数列
Niu Ke swipes questions and clocks in
Basic use of sringcloud & use of component Nacos
无向图的割点
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
KingbaseES ALTER TABLE 中 USING 子句的用法
JDBC courses
Infrared thermography temperature detection system based on arm rk3568
Inversion de l'intervalle spécifié dans la liste des liens
【第29天】给定一个整数,请你求出它的因子数
Basis of information entropy
异步、郵件、定時三大任務
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
Usage of using clause in kingbases alter table