当前位置:网站首页>8. Integer Decomposition
8. Integer Decomposition
2022-04-23 06:08:00 【linsa_ pursuer】
Give you an integer n, Split it into all its smallest factors ( Greater than 1) Multiplicative form of , At the same time, abide by the principle of minimum factor first , The small factor is in front , Such as n=6, The output 2*3=6.
package com;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
while (s.hasNextInt()){
System.out.println(mul(s.nextInt()));
}
}
public static String mul(int num){
StringBuilder sb = new StringBuilder();
String number = String.valueOf(num);
List<Integer> list = new LinkedList<Integer>();
for(int i=2;i<=num;i++){
while(num%i==0){
num/=i;
list.add(i);
}
}
for(int i=0;i<list.size();i++){
if(i==(list.size()-1)){
sb.append(list.get(i));
}else{
sb.append(list.get(i));
sb.append("*");
}
}
sb.append("=");
sb.append(number);
return sb.toString();
}
}
Such as :
Input :
5
6
24
Output :
5=5
2*3=6
2*2*2*3=24
版权声明
本文为[linsa_ pursuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533259725.html
边栏推荐
- The problem that the page will refresh automatically after clicking the submit button on the form is solved
- Ptorch learning record (XIII): recurrent neural network
- Chapter 4 of line generation - linear correlation of vector systems
- 2. Devops sonar installation
- The bottom implementation principle of thread - static agent mode
- How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
- Remedy after postfix becomes a spam transit station
- A sharp tool to improve work efficiency
- 在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
- 线性代数第二章-矩阵及其运算
猜你喜欢
Illustrate the significance of hashcode
In depth understanding of the relationship between dncblevel and noise denoising in the paper
Framework analysis 1 Introduction to system architecture
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
In depth source code analysis servlet first program
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images
Multithreading and high concurrency (3) -- synchronized principle
Best practices for MySQL storage time
Algèbre linéaire chapitre 1 - déterminants
随机推荐
Pytorch——数据加载和处理
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
How does MySQL convert stored seconds into dates
Reading of denoising paper - [ridnet, iccv19] real image denoising with feature attention
Exception handling: grab and throw model
Paper on Image Restoration - [red net, nips16] image restoration using very deep revolutionary encoder decoder networks wi
Numpy common function table sorting of data processing
A sharp tool to improve work efficiency
PyQt5学习(一):布局管理+信号和槽关联+菜单栏与工具栏+打包资源包
Kibana search syntax
Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
Get the value of state in effects in DVA
sklearn之 Gaussian Processes
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
MySQL basic madness theory
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
Pytorch learning record (XI): data enhancement, torchvision Explanation of various functions of transforms
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Pytorch学习记录(四):参数初始化
Practical operation - Nacos installation and configuration