当前位置:网站首页>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
边栏推荐
- Pytorch learning record (XI): data enhancement, torchvision Explanation of various functions of transforms
- Algèbre linéaire chapitre 2 - matrice et son fonctionnement
- Best practices for MySQL storage time
- Multithreading and high concurrency (3) -- synchronized principle
- Pytorch learning record (III): structure of neural network + using sequential and module to define the model
- 无监督去噪——[TMI2022]ISCL: Interdependent Self-Cooperative Learning for Unpaired Image Denoising
- Pyqy5 learning (2): qmainwindow + QWidget + qlabel
- container
- 对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
- Chapter 4 of line generation - linear correlation of vector systems
猜你喜欢
線性代數第一章-行列式
Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
Complete example demonstration of creating table to page - joint table query
PyQt5学习(一):布局管理+信号和槽关联+菜单栏与工具栏+打包资源包
Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
Kibana search syntax
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
Gaussian processes of sklearn
Pytorch learning record (XII): learning rate attenuation + regularization
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
随机推荐
How does MySQL convert stored seconds into dates
PyTorch入门小笔记——利用简单例子观察前向传播各个层输出的size
Pytorch learning record (III): structure of neural network + using sequential and module to define the model
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
去噪论文——[Noise2Void,CVPR19]Noise2Void-Learning Denoising from Single Noisy Images
The user name and password of users in the domain accessing the samba server outside the domain are wrong
解决报错:ImportError: IProgress not found. Please update jupyter and ipywidgets
What is the difference between the basic feasible solution and the basic feasible solution in linear programming?
治療TensorFlow後遺症——簡單例子記錄torch.utils.data.dataset.Dataset重寫時的圖片維度問題
在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
Kingdee EAS "general ledger" system calls "de posting" button
Pytorch learning record (IV): parameter initialization
给yarn配置国内镜像加速器
Create binary tree
数字图像处理基础(冈萨雷斯)一
Best practices for MySQL storage time
Why does the subscript of the array start from 0 instead of 1?
线性代数第三章-矩阵的初等变换与线性方程组
Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
Preparedstatement prevents SQL injection