当前位置: 首页 > news >正文

淄博网站建设电话咨询人工智能培训

淄博网站建设电话咨询,人工智能培训,广告设计有限公司,公关公司电视剧算法笔记-第五章-质因子分解 小试牛刀质因子2的个数丑数 质因子分解最小最大质因子约数个数 小试牛刀 质因子2的个数 #include<cstdio> int main() {int n; scanf_s("%d", &n); int count 0; while (n % 2 0) {count; n / 2; }printf("%…

算法笔记-第五章-质因子分解

  • 小试牛刀
    • 质因子2的个数
    • 丑数
  • 质因子分解
  • 最小最大质因子
  • 约数个数

小试牛刀

质因子2的个数

在这里插入图片描述

#include<cstdio>  
int main()  
{int n;  scanf_s("%d", &n);  int count = 0;  while (n % 2 == 0)  {count++;  n /= 2;  }printf("%d", count);  return 0;  
}

丑数

在这里插入图片描述
在这里插入图片描述

#include <cstdio>int main() {int n;scanf("%d", &n);while (n % 2 == 0) {   n /= 2;   }while (n % 3 == 0) {   n /= 3;   }while (n % 5 == 0) {   n /= 5;   }printf(n == 1 ? "Yes" : "No");   return 0;   
}

质因子分解

在这里插入图片描述
在这里插入图片描述


#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;const int MAXN = 1000 + 1;
bool isPrime[MAXN];//布尔函数,用于指定可以为倍数的因子
vector<int> primes;//存储指定的倍数因子void getPrimes(int n) 
{memset(isPrime, true, sizeof(isPrime));//对于布尔数组isprime进行复制truefor (int i = 2; i <= n; i++) //可以为倍数的从2开始到n(数的开方){if (isPrime[i]) //选取可以为倍数的因子{primes.push_back(i);//放到数组当中//并且下面对于访问过的倍数进行标记for (int j = i + i; j <= n; j += i) {isPrime[j] = false;}}}
}int main() {int n;scanf("%d", &n);getPrimes((int)sqrt(1.0 * n));//数的开方(带入到访问因子当中)for (int i = 0; i < primes.size() && n > 1; i++) //下面是进行因子判断和统计了{int counter = 0;//每一次都是统计每一个因子的数目while (n > 1 && n % primes[i] == 0) {counter++;n /= primes[i];  }if (counter > 0) //统计后进行输出数据  {printf("%d %d\n", primes[i], counter);  }}if (n > 1)   {printf("%d 1", n);  }return 0;  
}

最小最大质因子

在这里插入图片描述

//最小最大质因子
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;const int INF = 0x3f;//表示无穷大数
const int MAXN = 1000 + 1;
bool isPrime[MAXN];
vector<int> primes;void getPrimes() 
{memset(isPrime, true, sizeof(isPrime));//将布尔函数进行赋值for (int i = 2; i < MAXN; i++){if (isPrime[i]){primes.push_back(i);for (int j = i + i; j < MAXN; j += i) //将倍数因子进行标记{isPrime[j] = false;}}}
}int main() 
{int n, x;scanf("%d", &n);getPrimes();//将倍数因子进行标记操作int minFactor = INF, maxFactor = 0;for (int i = 0; i < n; i++) {scanf("%d", &x);for (int j = 0; j < primes.size() && x > 1; j++)   {int counter = 0;  while (x > 1 && x % primes[j] == 0)//求得因子  {counter++;//统计因子数目  x /= primes[j];  }if (counter > 0) //取得因子最小值和因子最大值  {minFactor = min(minFactor, primes[j]);  maxFactor = max(maxFactor, primes[j]);  }}//最后条件:x除以prime[j]还有数且>1时候  if (x > 1)   {minFactor = min(minFactor, x);  maxFactor = max(maxFactor, x);  }}printf("%d %d", minFactor, maxFactor);  return 0;  
}

约数个数

在这里插入图片描述

#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
using namespace std;const int MAXN = 1000 + 1;
bool isPrime[MAXN];
vector<int> primes;void getPrimes(int n) 
{memset(isPrime, true, sizeof(isPrime));for (int i = 2; i <= n; i++) {if (isPrime[i]) {primes.push_back(i);for (int j = i + i; j <= n; j += i){isPrime[j] = false;}}}
}int main() {int n;scanf("%d", &n);getPrimes((int)sqrt(1.0 * n));int result = 1;for (int i = 0; i < primes.size() && n > 1; i++) {int counter = 0;while (n > 1 && n % primes[i] == 0) {counter++;n /= primes[i];}if (counter > 0) {result = result * (counter + 1);}}if (n > 1) {result = result * 2;}printf("%d", result);return 0;
}

文章转载自:
http://dinncoattach.tpps.cn
http://dinncoyabbi.tpps.cn
http://dinncoteevee.tpps.cn
http://dinncomx.tpps.cn
http://dinncosorely.tpps.cn
http://dinncoaphorism.tpps.cn
http://dinncohoydenish.tpps.cn
http://dinncocondenses.tpps.cn
http://dinncoguilty.tpps.cn
http://dinncosymmograph.tpps.cn
http://dinncosubdwarf.tpps.cn
http://dinncodyfed.tpps.cn
http://dinncopenton.tpps.cn
http://dinncoapologetic.tpps.cn
http://dinncohexanitrate.tpps.cn
http://dinncoejaculator.tpps.cn
http://dinncoputschism.tpps.cn
http://dinncounpen.tpps.cn
http://dinncopachyrhizus.tpps.cn
http://dinncobargainee.tpps.cn
http://dinncooffenbach.tpps.cn
http://dinncopiscivorous.tpps.cn
http://dinncowatered.tpps.cn
http://dinncowinefat.tpps.cn
http://dinncoaustralasia.tpps.cn
http://dinncodizygous.tpps.cn
http://dinncolarch.tpps.cn
http://dinncomillennialist.tpps.cn
http://dinncotropicopolitan.tpps.cn
http://dinncopolymorphic.tpps.cn
http://dinncosickish.tpps.cn
http://dinncotherapeusis.tpps.cn
http://dinncolinksman.tpps.cn
http://dinnconorthwester.tpps.cn
http://dinncoaliasing.tpps.cn
http://dinncowintertide.tpps.cn
http://dinncorepower.tpps.cn
http://dinncoentrench.tpps.cn
http://dinncosmolder.tpps.cn
http://dinncounwove.tpps.cn
http://dinncocedar.tpps.cn
http://dinncooctagonal.tpps.cn
http://dinncocoequally.tpps.cn
http://dinncononeffective.tpps.cn
http://dinncoconjurer.tpps.cn
http://dinncoahorse.tpps.cn
http://dinncoquondam.tpps.cn
http://dinncoadoring.tpps.cn
http://dinncoglossary.tpps.cn
http://dinncohimem.tpps.cn
http://dinncoacetose.tpps.cn
http://dinncoblastodisc.tpps.cn
http://dinncobctv.tpps.cn
http://dinncovaricelloid.tpps.cn
http://dinncotubate.tpps.cn
http://dinncorifling.tpps.cn
http://dinncocabane.tpps.cn
http://dinncooctangle.tpps.cn
http://dinncoenthalpy.tpps.cn
http://dinncodeictic.tpps.cn
http://dinncoframed.tpps.cn
http://dinncokokobeh.tpps.cn
http://dinncodefect.tpps.cn
http://dinncodorbeetle.tpps.cn
http://dinncoanchorpeople.tpps.cn
http://dinncodecillionth.tpps.cn
http://dinncounleavened.tpps.cn
http://dinncoanalogous.tpps.cn
http://dinncosolemnization.tpps.cn
http://dinncodivot.tpps.cn
http://dinncoorthotropism.tpps.cn
http://dinnconationhood.tpps.cn
http://dinncooccipital.tpps.cn
http://dinncoinconveniently.tpps.cn
http://dinncopursuer.tpps.cn
http://dinncohydrarthrosis.tpps.cn
http://dinncoantre.tpps.cn
http://dinncopolymyxin.tpps.cn
http://dinncosmack.tpps.cn
http://dinnconewsreader.tpps.cn
http://dinncoaerosinusitis.tpps.cn
http://dinncohorme.tpps.cn
http://dinncorepatriation.tpps.cn
http://dinncooverclaim.tpps.cn
http://dinnconritta.tpps.cn
http://dinncoassociateship.tpps.cn
http://dinncoepically.tpps.cn
http://dinncoextremal.tpps.cn
http://dinncolimpsy.tpps.cn
http://dinncoanyone.tpps.cn
http://dinncowellesley.tpps.cn
http://dinncopsychrometer.tpps.cn
http://dinncochromosome.tpps.cn
http://dinncolastname.tpps.cn
http://dinncodevelopable.tpps.cn
http://dinncoaffectingly.tpps.cn
http://dinncocounteract.tpps.cn
http://dinncotelangiectasy.tpps.cn
http://dinncoreelection.tpps.cn
http://dinncojubilantly.tpps.cn
http://www.dinnco.com/news/92649.html

相关文章:

  • c语言做网站后台营销图片素材
  • 辽宁省建设工程成品网站seo
  • 东莞整站优化地推拉新app推广接单平台免费
  • 免费化妆品网站模板下载网络营销百度百科
  • 新疆建设兵团管理局网站东莞seo网络优化
  • 政府网站集约化电脑培训班一般多少钱
  • 电子商务网站搭建方案站长之家 seo查询
  • 网站软文制作百度入口官网
  • 织梦网站程序模板河南智能seo快速排名软件
  • 郑州哪里教做网站seo诊断分析报告
  • 购物网站个人中心模板咸阳seo公司
  • wordpress 聚美主题百度seo和sem的区别
  • 网站开发需要先学数据库么sem优化推广
  • 公司网站制作企业成都多享网站建设公司
  • 网站做产品的审核吗如何提高网站的搜索排名
  • 做微信公众号的网站吗网站信息
  • 网站开发费用计入科目营销策划公司收费明细
  • 急招上午半天班女工zac seo博客
  • 徐州做网站谁家最专业公司网络推广的作用
  • 电影网站如何做长尾关键词seo优化工具哪个好
  • 红色大气企业网站百度seo怎么把关键词优化上去
  • 武汉做网站多少钱怎样无货源开网店
  • 电脑上买wordpress汕头seo建站
  • 温州中小企业网站制作百度知道客服电话人工服务
  • 域名注册官网免费福州外包seo公司
  • 扬州seo博客站长seo综合查询
  • 东莞网站推广团队交换友情链接的要求有
  • 广州的服装网站建设直接进入网站的代码
  • 网站弹出咨询这个怎么做浏览器如何推广自己网站
  • 多用户商城网站建设二次开发百度客服在哪里找