首页 > 其他分享 >质因数

质因数

时间:2022-09-04 20:57:37浏览次数:50  
标签:std map begin end int 质因数

分解质因数

#include<bits/stdc++.h>
using namespace std;
int n;
map<int,int> M;
void f(int x){
	for(int i=2;i<=sqrt(x);i++){
		while(x%i==0){
			M[i]++;
			x/=i;
		}
	}
	if(x!=1)M[x]++;
	for(map<int,int>::iterator it=M.begin();it!=M.end();it++){
		cout<<it->first<<","<<it->second<<endl;
	}
}
int main(){
    cin>>n;
    f(n);
    return 0;
}

标签:std,map,begin,end,int,质因数
From: https://www.cnblogs.com/hnzzlxs01/p/16656039.html

相关文章

  • 问题 N: Number Multiplication --Pollard-Rho算法质因数分解
    问题N:NumberMultiplication题意:给你m个M点,n个N点,M都是质数,N是和它相连的M的乘积,然后告诉你每个N点的值,求M点直接对每个N分解质因数即可,测试欧拉筛筛到4e7再......
  • 质因数+树形DP例题
    题目:https://www.codechef.com/submit/MAKEIT1?tab=statement题解:https://www.codechef.com/submit/ROCKET_PACK?tab=solution代码:#include<bits/stdc++.h>#includ......
  • 质因数分解-函数
    题目描述原题来自:NOIP2012普及组 已知正整数n 是两个不同的质数的乘积,试求出较大的那个质数。输入格式输入只有一行,包含一个正整数n 。输出格式输......