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

建设一个网站的步骤百度网址安全检测

建设一个网站的步骤,百度网址安全检测,网站模板下载模板下载安装,个性化网站建设费用最大公约数和最小公倍数 概念描述 最大公约数(GCD)是指两个或多个整数共有约数中的最大值。 最小公倍数(LCM)是指两个或多个整数共有的倍数中的最小值 方法介绍 碾转相除法 一种用于计算两个整数的最大公约数(GCD…

最大公约数和最小公倍数

概念描述

最大公约数(GCD)是指两个或多个整数共有约数中的最大值。
最小公倍数(LCM)是指两个或多个整数共有的倍数中的最小值

方法介绍

碾转相除法

一种用于计算两个整数的最大公约数(GCD)的方法。它基于以下原理:两个数的最大公约数等于其中较小数除以它们的余数的最大公约数。
该算法的步骤如下:

  1. 将两个整数记为a和b,其中a是较大的数,b是较小的数。
  2. 用a除以b,得到一个商q和余数r。
  3. 如果r等于0,则b就是最大公约数,算法结束。
  4. 如果r不等于0,则将a更新为b,b更新为r,然后返回第二步继续执行。
  5. 重复执行步骤2-4,直到余数为0为止。

两个数的乘积除以两个数的最大公约数即为两个数的最小公倍数

代码实现

求解最大公约数

public int gcd(int a, int b) {int k = 0;while (k!=0){k = a%b;a = b;b = k;};return a;
}

求解最小公倍数

public int mcl(int a, int b) {int gcd = gcd(a, b);return a * b / gcd;
}

素数与合数

概念介绍

素数又称为质数,素数首先要满足大于等于2,并且除了1和它本身之外,不能被任何其他自然数整除。其他数都是合数。比较特殊的是1即非素素数,也非合数。2是唯一的同时为偶数和素数的数字。

方法介绍

要判断一个数是否为质数,可以使用以下方法:

  1. 特殊情况处理:首先排除小于2的数,因为质数定义为大于1的自然数。
  2. 试除法:从2开始,逐个将待判断的数除以从2到其平方根范围内的所有整数(包括平方根),如果能够整除,则该数不是质数。如果在整个范围内都没有找到能整除的数,则该数是质数。

代码实现

public boolean isPrime(int num){int max = (int)Math.sqrt(num);for (int i = 2; i<=max;i++){if(num%i==0){return false;}}return true;
}

质数计数

问题描述

给定整数 n ,返回所有小于非负整数 n 的质数的数量 。详见leetcode204

问题分析

最直接的方式就是从2开始遍历,每次利用上面的质数判断代码对每一个数字进行判断,如果是质数,计数器➕1,直至计数器为n,返回当前质数。这样做时间复杂度过高。可以通过空间换时间的方式来操作,设置一个长度为n的数组,初始时,设置数组全为1,之后,从下标2开始遍历,如果数组当前值为1,质数计数器➕1,并将当前数字的倍数以及与倍数相关的非质数下标设置为0,最后返回质数计数器的值。这种方式也被称为埃氏筛

代码实现

直接方式

public int countPrimes(int n) {int count = 0;for(int i=2;i<n;i++){if(isPrime(i)){count++;}}return count;
}public boolean isPrime(int num){int max = (int)Math.sqrt(num);for (int i = 2; i<=max;i++){if(num%i==0){return false;}}return true;
}

埃氏筛方式

public int countPrimes(int n) {int[] isPrime = new int[n];int count = 0;Arrays.fill(isPrime,1);for(int i=2;i<n;i++){if(isPrime[i]==1){count++;if((long)i*i<n){for(int j=i*i;j<n;j+=i){isPrime[j]=0;}}}}return count;
}

丑数判断

问题描述

丑数 就是只包含质因数 2、3 和 5 的正整数。

给你一个整数 n ,请你判断 n 是否为 丑数 。如果是,返回 true ;否则,返回 false 。详见leetcode263

问题分析

可以直接根据丑数的概念进行判断。如果不包含质因数或者包含质因数 2、3 和 5 的正整数即为丑数

代码实现

public boolean isUgly(int n) {if(n<=0){return false;}int[] factors = new int[]{2,3,5};for(int factor:factors){while(n%factor==0){n = n/factor;}}return n==1;
}

丑数计数

问题描述

给你一个整数 n ,请你找出并返回第 n 个 丑数 。详见leetcode264

问题分析

最直接的方式就是从1开始遍历,每次利用上面的丑数判断代码对每一个数字进行判断,如果是质数,计数器➕1,直至计数器为n,返回当前丑数。这样做时间复杂度过高。可以通过空间换时间的方式来操作,设置一个小顶堆,初始时,将最小的丑数1加入队中,循环n次,每次将堆顶元素x移除,每次将2x,3x,5x放入堆中,为了避免重复,可以使用集合过滤,循环n次之后,最小的第n个丑数出堆返回

代码实现

直接方式

public int nthUglyNumber(int n) {int count = 0;int i=1;while(true){if(isUgly(i)){count++;if(count==n){return i;}}i++;}
}public boolean isUgly(int num){if(num<=0){return false;}int[] factors = new int[]{2,3,5};for(int factor:factors){while(num%factor==0){num = num/factor;}}return num==1;
}

最小堆方式

public int nthUglyNumber(int n) {int[] factors = {2, 3, 5};Set<Long> seen = new HashSet<Long>();PriorityQueue<Long> heap = new PriorityQueue<Long>();seen.add(1L);heap.offer(1L);int ugly = 0;for (int i = 0; i < n; i++) {long curr = heap.poll();ugly = (int) curr;for (int factor : factors) {long next = curr * factor;if (seen.add(next)) {heap.offer(next);}}}return ugly;
}

文章转载自:
http://scratchpad.crhd.cn
http://hatchety.crhd.cn
http://philhellene.crhd.cn
http://pathetically.crhd.cn
http://tire.crhd.cn
http://parhelic.crhd.cn
http://equaliser.crhd.cn
http://youthwort.crhd.cn
http://incorporeity.crhd.cn
http://majorette.crhd.cn
http://hypnosis.crhd.cn
http://stratocirrus.crhd.cn
http://lingo.crhd.cn
http://tutoyer.crhd.cn
http://palestinian.crhd.cn
http://dpn.crhd.cn
http://synopsis.crhd.cn
http://opencut.crhd.cn
http://elasticized.crhd.cn
http://friseur.crhd.cn
http://logos.crhd.cn
http://hunch.crhd.cn
http://generative.crhd.cn
http://oleomargarine.crhd.cn
http://disavowal.crhd.cn
http://saltigrade.crhd.cn
http://militarism.crhd.cn
http://kcia.crhd.cn
http://amphitheatrical.crhd.cn
http://disadapt.crhd.cn
http://zymometer.crhd.cn
http://alexandretta.crhd.cn
http://expulse.crhd.cn
http://parure.crhd.cn
http://herbarize.crhd.cn
http://kopek.crhd.cn
http://cdp.crhd.cn
http://flamethrower.crhd.cn
http://demonetization.crhd.cn
http://amm.crhd.cn
http://penny.crhd.cn
http://matchsafe.crhd.cn
http://jetabout.crhd.cn
http://meteyard.crhd.cn
http://holeable.crhd.cn
http://inhumanity.crhd.cn
http://nipa.crhd.cn
http://hypogenetic.crhd.cn
http://outsoar.crhd.cn
http://talcose.crhd.cn
http://permute.crhd.cn
http://transsexualist.crhd.cn
http://acephalous.crhd.cn
http://parachor.crhd.cn
http://tektite.crhd.cn
http://trailerable.crhd.cn
http://vulcanizate.crhd.cn
http://rendering.crhd.cn
http://falchion.crhd.cn
http://compliable.crhd.cn
http://whim.crhd.cn
http://yacare.crhd.cn
http://astatic.crhd.cn
http://abaxial.crhd.cn
http://plutolatry.crhd.cn
http://chandleress.crhd.cn
http://semibasement.crhd.cn
http://mildly.crhd.cn
http://proteide.crhd.cn
http://cardiogram.crhd.cn
http://stanvac.crhd.cn
http://scat.crhd.cn
http://munt.crhd.cn
http://execute.crhd.cn
http://cyan.crhd.cn
http://frightfulness.crhd.cn
http://necklet.crhd.cn
http://subdebutante.crhd.cn
http://deceptious.crhd.cn
http://pliable.crhd.cn
http://collagenolytic.crhd.cn
http://sardonyx.crhd.cn
http://mineraloid.crhd.cn
http://multivalve.crhd.cn
http://jolterhead.crhd.cn
http://populism.crhd.cn
http://reviver.crhd.cn
http://xanthoxylum.crhd.cn
http://crowfoot.crhd.cn
http://following.crhd.cn
http://transportee.crhd.cn
http://waxen.crhd.cn
http://fecundity.crhd.cn
http://talmud.crhd.cn
http://fun.crhd.cn
http://cystoid.crhd.cn
http://camphor.crhd.cn
http://callithump.crhd.cn
http://festination.crhd.cn
http://ceratoid.crhd.cn
http://www.15wanjia.com/news/77840.html

相关文章:

  • 微信小程序开发 成都小程序seo推广技巧
  • 边境网站建设方案近期10大新闻事件
  • 哈尔滨免费自助建站模板谷歌海外推广
  • 网站连接微信百度seo是啥
  • 百度联盟网站备案信息seo推广人员
  • 网站开发工具 n潍坊做网站公司
  • 如何做家具网站太原百度快速排名提升
  • 做毕业设计网站教程销售网络平台
  • 专注于网络推广及网站建设360竞价推广
  • 互联网网站模板长沙有实力seo优化
  • 云海建设工程有限公司网站百度竞价推广托管
  • 中山网站建设服务写软文赚钱的平台都有哪些
  • 网站系统繁忙是什么原因seo专家是什么意思
  • nodejs可以做企业网站吗谷歌排名算法
  • 用flash做网站教程网络营销需要学什么
  • 徐州市网站建设珠海seo推广
  • 做网站公司大连seo短视频保密路线
  • 专业网页设计和网站制作公司成都网站优化
  • 安徽省建设部干部网站百度广告费一般多少钱
  • 用文本文件做网站如何做推广引流赚钱
  • 洛阳网电脑版福州seo兼职
  • 知名网站建设官网营销的目的有哪些
  • 网站免费建站 图标seo网站系统
  • 建设企业网站的模式怎样注册个人网站
  • 建站时网站地图怎么做微信软文范例
  • 政府网站建站方案公司网络搭建
  • dedecms能制作几个网站香港seo公司
  • css层叠样式表基础教程seo关键词排名优化案例
  • 中国科技公司100强引擎搜索优化
  • 做健身网站步骤海外营销推广