首页 > 其他分享 >Prime factorization of a number【1月19日学习笔记】

Prime factorization of a number【1月19日学习笔记】

时间:2024-01-19 17:23:26浏览次数:22  
标签:Prime 19 number factorization int primefactorization

点击查看代码
//Prime factorization of a number
#include<iostream>
#include<cmath>
using namespace std;

void primefactorization(int n) {
	for (int i = 2; i <= sqrt(n); i++) {//质因数(除去本身)只可能在根号n及其左侧
		if (n % i == 0) {//i从2开始,短除法
			int count = 0;
			while (n % i == 0) {//连续除以i至不能整除
				n = n / i;
				count++;//记录指数
			}
			cout << i << "^" << count << " ";
		}
	}
	if (n != 1)  cout << n << "^" << 1;//最终的商,1或质因数(因为上面只循环到了根号n,所以会出现商为1的情况)
	cout << endl;
}//时间复杂度:O(sqrt(n))

int main() {
	int n;
	cin >> n;
	primefactorization(n);
}

标签:Prime,19,number,factorization,int,primefactorization
From: https://www.cnblogs.com/whvivy/p/17975134

相关文章

  • Adobe InDesign 2024 v19.1 (macOS, Windows) - 版面设计和桌面出版软件
    AdobeInDesign2024v19.1(macOS,Windows)-版面设计和桌面出版软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、Adob......
  • Adobe InCopy 2024 v19.1 (macOS, Windows) - 编写和副本编辑软件
    AdobeInCopy2024v19.1(macOS,Windows)-编写和副本编辑软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、AdobeXD......
  • Find all factors of a number【1月19日学习笔记】
    点击查看代码//Findallfactorsofanumber#include<iostream>#include<cmath>usingnamespacestd;voidFactors(intn){ int*factors=newint[n+1](); for(inti=1;i<=sqrt(n);i++){//检测一侧因子即可 if(n%i==0){ factors[i-1]=i;//问......
  • dotnet 8项目Docker部署报错 Unhandled exception. Microsoft.Data.SqlClient.SqlExce
    环境:dotnet8+sqlserver2012本地开发调试正常,部署至Docker容器时,运行实例报错。查看日志显示:Unhandledexception.Microsoft.Data.SqlClient.SqlException(0x80131904):Aconnectionwassuccessfullyestablishedwiththeserver,butthenanerroroccurredduringth......
  • 【2024.01.19】huginn爬取什么值得买的排行榜
    一句命令就行,主要是搭配RSS使用dockerrun-d-p3000:3000ghcr.io/yhdsl/huginn:latest这次主要是为了自定义爬取内容筛选掉一些我用不上的,比如说奶粉啥的{"schema_version":1,"name":"什么值得买榜单","description":"关键词里面自己修改","source_url&qu......
  • 20240119
    卡常狗能不能死一死啊A.构造87bitset瞎搞#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong#defineullunsignedlonglong#defineALL(a)(a).begin(),(a).end()#definepbpush_back#definemkmake_pair#definepiipair<int,int>#define......
  • Convert a number from decimal to binary【1月19日学习笔记】
    点击查看代码//Convertanumberfromdecimaltobinary#include<iostream>usingnamespacestd;structnode{ intdata; node*next;};node*A;voidinsert(intx){ node*temp=newnode; temp->data=x; temp->next=NULL; if(A==NULL){ A......
  • 1.19学习进度
    1.standalone是一个完整的分布式集群环境;standalone集群在进程上主要有三类进程:主节点master及昵称、从节点的worker进程、历史服务器哦historyserver(可选)2.4040:是一个运行的application在运行的过程中临时绑定的端口,用以查看当前任务的状态。4040被占用会顺延到4041、4042等。404......
  • Quick sort【1月19日学习笔记】
    点击查看代码//Quicksort#include<iostream>usingnamespacestd;intpartition(intA[],intstart,intend){ intpivot=A[end];//默认选取末尾为主元 intpIndex=start;//分区索引初始化 for(inti=start;i<end;i++){//从索引start开始扫描 if(A[i]<......
  • 2024-1-19事件绑定,input与hover事件
    目录事件绑定,input与hover事件事件绑定hover事件input事件事件绑定.on()方法注意:off()方法事件绑定,input与hover事件在jQ内很多中事件常用的事件有下面的click(function(){...})//绑定一个点击事件hover(function(){...})//悬停触发事件blur(function(){...})//失焦事件处理......