当前位置:网站首页>Basic exercise decomposing prime factors
Basic exercise decomposing prime factors
2022-06-12 09:05:00 【Record dada I】
Resource constraints
The time limit :1.0s Memory limit :512.0MB
Problem description
Find the interval [a,b] The prime factorization of all integers in .
Input format
Enter two integers a,b.
## Output format
Each line outputs a decomposition of numbers , Form like k=a1a2a3…(a1<=a2<=a3…,k From small to large )( See the example for details )
The sample input
3 10
Sample output
3=3
4=22
5=5
6=23
7=7
8=222
9=33
10=25
Tips
Let's sift out all the prime numbers first , And then break it down .
Data size and engagement
2<=a<=b<=10000
Code
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int count(int n)// Find each factor
{
int m = sqrt(n);
for(int i=2;i<=m;i++)
{
if(n%i==0)
{
return i;
}
}
return n;
}
int main()
{
int a,b;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
int j=count(i);
int k = i/j;// See if it can be decomposed
cout<<i<<"="<<j;
while(k>1)// Decomposable
{
j=count(k);// Look for factors
cout<<"*"<<j;
k=k/j;// Cyclic factor finding until 1( It can't be broken down )
}
cout<<endl;
}
return 0;
}
边栏推荐
- Redis installation test
- Convert spaces to < br / > newline labels
- Unittest测试框架
- Get last month, current time and next month
- Box model border
- Background position - mixed units
- Binlog in mysql:
- Domain name mapping to specified IP
- IP, DNS, domain name, URL, hosts
- Introduction to Chang'an chain node certificate, role and authority management
猜你喜欢

利用nvm动态调整nodejs版本,解决因为node版本过高或过低导致项目无法运行和打包

Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?

Background color translucent

List < string > sort
![Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps](/img/0a/65bc44850e52204af278e50a8f86eb.jpg)
Sword finger offer:[day 8 dynamic planning (simple)] --- > frog jumping on steps

Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"

Problems that cannot be resolved by tar command

Introduction to applet cloud development -- questionnaire evaluation applet practice (7)

Multi table operation instance

《MATLAB 神经网络43个案例分析》:第8章 GRNN网络的预测----基于广义回归神经网络的货运量预测
随机推荐
128. 最長連續序列-哈希錶
Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"
Top command meaning
day5-x
解决当打开Unity时 提示项目已经打开,而自己之前并没有打开过(可能之前异常关闭)的问题
The newline character with in the string is converted to an array
Unittest test framework
MFS详解(四)——MFS管理服务器安装与配置
Flink passes in custom parameters or profiles
ip、DNS、域名、URL、hosts
128. 最长连续序列-哈希表
第五章-[bx]和Loop指令
torch. logical_ And() method
Building a cluster: and replacing with error
Binary tree calculation problem
Chapter V -[bx] and loop instructions
Grab screen and ground glass effect
Sword finger offer:[day 9 dynamic planning (medium)] --- > maximum sum of continuous subarrays
(十五) TweenRunner
Set up redis sentinel cluster (instance):