打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c++正整数因式分解

最新c++正整数因式分解

以下是三零网为大家整理的最新c++正整数因式分解的文章,希望大家能够喜欢!

#include <iostream>
#include <map>
#include <set>

using namespace std;

void fact(int a, map<int, int>& result);

int main()
{
int a = 1025;
map<int, int> m;
fact(a, m);

cout << a << " = ";
for(map<int, int>::const_iterator it = m.begin(); it != m.end(); it++)
{
cout << it->first << "^" << it->second << " ";
}
cout << endl;

cin.get();
}

void fact(int a, map<int, int>& result)
{
multiset<int> exp;
while(a > 1)
{
for(int i = 2; i <= a; i++)
{
if(0 == a % i)
{
a = a / i;
exp.insert(i);
break;
}
}
}

for(multiset<int>::iterator it = exp.begin(); it != exp.end(); )
{
result.insert(make_pair(*it, exp.count(*it)));
it = exp.upper_bound(*it);
}
}
 


延伸阅读:
·C语言经典算法 - 因式分解
·c语言 输出所有小于n(n>=2正整数)的素数
·C语言输入两个正整数m和n,求其最大公约数和最小公倍数
·C语言将一个正整数分解质因数
·c++ 输入两个正整数m和n,求其最大公约数和最小公倍数
·C语言正整数转换成罗马数字

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
十字相乘法
八上数学每日一练:因式分解的应用练习题及答案_2020年填空题版.pdf
七年级数学下册《因式分解》练习题及答案(冀教版)
专题08 中考数学初中数学复习考点精讲热考题型专项训练 整式的乘除与因式分解(专题测试)(原卷版)
位运算之美
初中奥数经典代数部分精选
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服