首页 > 其他分享 >数论的各种板子1.0

数论的各种板子1.0

时间:2024-04-02 22:30:14浏览次数:22  
标签:约数 1.0 shu 数论 板子 break int shai

仅为了记录所学的知识.

bool is_prime(int x){//求是否为素数 
	if(x<2) return false;
	for(int i=2;i<=x/i;++i){
		if(x%i==0) return false;
	}
	return true;
}

void divide(int x){//分解质因子 
	for(int i=2;i<=x/i;++i){
		int s=0;
		while(x%i==0) x/=i,s++;
		cout<<i<<' '<<s<<endl;
	}
	if(x>1) cout<<x<<' '<<1<<endl;
	cout<<endl;
}

void shai1(int x){//朴素筛
	for(int i=2;i<=n;++i){
		if(x%i==0){
			shu[cnt++]=i;
			for(int j=2;j<=n;j++){
				if(i*j>n) break;
				shai[i*j]=1;
			}
		}
	}
}

void shai2(int x){//欧拉筛 
	for(int i=2;i<n;i++){
		if(x%i==0) shu[cnt++]=i;
		for(int j=1;j<n;j++){
			if(shu[j]*i>n) break;
			shai[shu[j]*i]=1;
			if(shu[j]*i==0) break;
		}
	}
}

vector<int> get_divisors(int x){//分解因数,求所有约数 
	vector<int>res;//存答案 
	for(int i=1;i<=x/i;++i){
		if(x%i==0){//如果可以整除 
			res.push_back(i);//推入 
			if(i!=x/i) res.push_back(x/i);//如果不是平方的结果,推入 
		} 
	}
	//sort(res.begin(),res.end()); 不要求顺序的话,不用排序 
	return res;
}

标签:约数,1.0,shu,数论,板子,break,int,shai
From: https://blog.csdn.net/2302_80928106/article/details/137204600

相关文章

  • 最短路径问题(单源最短路问题-都正边)1.0
    基本思路和代码来自y总!朴素版dijkstra算法适合与稠密图,用邻接矩阵来存图#include<bits/stdc++.h>#include<algorithm>usingnamespacestd;intn,m;//intg[520][520];//存图边的值intdist[520];//存最短距离boolst[520];//是否已经遍历过最小的边intdijks......
  • 数论分块学习笔记
    数论分块学习笔记性质数论分块用于快速计算含有除法向下取整的和式,即形如\(\sum_{i=1}^nf(i)g(\lfloor\frac{n}{i}\rfloor)\)的式子。当预处理出\(f\)的前缀和时,数论分块可以在\(O(\sqrt{n})\)的时间复杂度下计算上述和式的值。求解引理\(1\):\(\foralla,b,c\in\math......
  • 查询语句,在Hive版本3.1.0中执行报错,在Hive版本3.1.2中执行成功
    第3条语句执行查询,在Hive版本3.1.0中执行报错:Error:Errorwhileprocessingstatement:FAILED:ExecutionError,returncode2fromorg.apache.hadoop.hive.ql.exec.mr.MapRedTask(state=08S01,code=2),在Hive版本3.1.2中执行成功。新建表CREATETABLEuser_test(cr......
  • 状压dp板子(cf div4 #937)
    #include<bits/stdc++.h>usingnamespacestd;intn;vector<int>v[20];stringa[20],b[20];booldp[500010][20];voiddfs(ints,intnow){dp[s][now]=true;for(autonxt:v[now]){if(s&(1<<nxt))continue;......
  • kmp板子
    书上讲的感觉不好理解,不如算法竞赛上分析的题目链接:https://www.luogu.com.cn/problem/P3375贴板子:#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<string.h>#include<i......
  • Ubuntu下本机向minicom板子传文件操作
    1.配置minicomlingd@ubuntu:~$  sudominicom-s    出现这样的配置界面:       +-----[configuration]------+       |Filenamesandpaths   |       |Filetransferprotocols |       |Serialport......
  • 前端自动部署报错“http://registry.npm.taobao.org/****/download/array-tree-filter
    自动部署时报错我试过更改淘宝镜像为https://registry.npmmirror.com但都不生效报错如下图:代码中的配置文件如下如上配置在其他测试环境均正常,只在生产环境报错求大佬帮忙看看是什么原因呀......
  • Astah Professional 9.1.0 x64
    AstahProfessional9.1.0x6424May20230CommentsProgrammingAstah, Astahcrack, Astahcrackdownload, Astahdownload, Astahfree, Astahfreedownload, Astahfullcrack, Astahpatch 4.3/5-(2982votes)DownloadatMAXIMUM......
  • 图论板子
    链式前向星的存储模板#include<iostream>#include<vector>#include<algorithm>#include<math.h>#include<sstream>#include<string>#include<string.h>#include<iomanip>#include<stdlib.h>#include<map>#inclu......
  • ubuntu编译与安装 OpenSSL-1.0.0
    apt-getpurgeopensslrm-rf/etc/ssl#删除配置文件编译与安装OpenSSLprefix是安装目录,openssldir是配置文件目录,另外建议安装两次,shared作用是生成动态连接库。(需要同时指定prefix与openssldir,否则可能会因为找不到文件而报错)wgetftp://ftp.openssl.org/source/op......