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

Find all factors of a number【1月19日学习笔记】

时间:2024-01-19 16:26:10浏览次数:20  
标签:Factors 19 factors number int Find

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

void Factors(int n) {
	int* factors = new int[n+1]();
	for (int i = 1; i <= sqrt(n); i++) {//检测一侧因子即可
		if (n % i == 0) {
			factors[i-1] = i;//问题:动态数组为n时显示缓冲区溢出
			if (i != sqrt(n))
				factors[n / i-1] = n / i;//成对放入,减少循环
		}
	}
	for (int i = 0; i <n; i++) {
		if (factors[i] != 0)
			cout << factors[i] << " ";//输出从小到大
	}
	cout << endl;
	delete []factors;
}//时间复杂度:O(sqrt(n))

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

标签:Factors,19,factors,number,int,Find
From: https://www.cnblogs.com/whvivy/p/17974927

相关文章

  • 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(){...})//失焦事件处理......
  • 2024.1.19日报
    本质:启动一个JVMProcess进程(一个进程里有多个线程),执行任务TaskLocal模式可以限制模拟Spark集群环境的线程数量,即Local[N]或Local[*]其中N代表可以使用N个线程,每个线程拥有一个cpucore,如果不指定N,则默认是1个线程(该线程有一个core)。通常Cpu有几个core,就指定几个线程,最大化利用......
  • 2024-1-19事件绑定,input与hover事件
    目录事件绑定,input与hover事件事件绑定hover事件input事件事件绑定,input与hover事件在jQ内很多中事件常用的事件有下面的click(function(){...})//绑定一个点击事件hover(function(){...})//悬停触发事件blur(function(){...})//失焦事件处理focus(function(){...})//焦点......
  • 16 Battling with Numbers
    组合数(2次方级)的组合#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintmod=998244353;voidsolve(){ intn; cin>>n; vector<int>a(n+1); for(inti=1;i<=n;i++)cin>>a[i]; map<int,int>mp; for(inti=1;i&l......