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

算法学习笔记(1):组合数

 暴力题解 --时间复杂度O(nlogn)。

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long longsigned main(){int n;cin>>n;int ans=0;for(int i=2;i<=n;i+=2){int x=i;while(x%2==0){ans++;x/=2;}}cout<<ans;
}

 正解算法--Legendre 公式(勒让德公式 )

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long longsigned main(){int n;cin>>n;int ans=0;while(n){ans+=n/2;n/=2;}//即让n/2/4/8/16cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long longsigned main(){//同理可知,算n!内有几个10相乘,即多少个2和多少个5能相乘int n;cin>>n;int ans=0;int a2=0,a5=0;int x;x=n;while(x){a2+=x/2;x/=2;}x=n;while(x){a5+=x/5;x/=5;}ans+=min(a2,a5);cout<<ans;
}


文章转载自:
http://carbinol.jopebe.cn
http://affinitive.jopebe.cn
http://arpeggio.jopebe.cn
http://cambric.jopebe.cn
http://billiards.jopebe.cn
http://boater.jopebe.cn
http://buoyant.jopebe.cn
http://babiche.jopebe.cn
http://cachepot.jopebe.cn
http://bavin.jopebe.cn
http://atmometric.jopebe.cn
http://changeably.jopebe.cn
http://causally.jopebe.cn
http://antibody.jopebe.cn
http://anticipate.jopebe.cn
http://alkalinity.jopebe.cn
http://angleworm.jopebe.cn
http://autotransformer.jopebe.cn
http://alliterative.jopebe.cn
http://assure.jopebe.cn
http://cacodylate.jopebe.cn
http://bield.jopebe.cn
http://aerobus.jopebe.cn
http://ancress.jopebe.cn
http://celebes.jopebe.cn
http://bones.jopebe.cn
http://alt.jopebe.cn
http://aback.jopebe.cn
http://butty.jopebe.cn
http://cesspit.jopebe.cn
http://www.dtcms.com/a/281326.html

相关文章:

  • 论文 视黄素与细胞修复
  • 可下载或通过爬虫获取疾病相关数据的网站及平台,涵盖临床数据、基因关联、药品信息等方向,并附注数据特点与获取方式:(不公开)
  • PHP安全漏洞深度解析:文件包含与SSRF攻击的攻防实战
  • keeplived双击热备配置
  • chrome浏览器(chrome138.0.0.0 )无法安装扩展程序,因为它使用了不受支持的清单版本解决方案
  • GAMES101 lec2-数学基础1(线性代数)
  • 03 51单片机之独立按键控制LED状态
  • HCIA第三次综合实验:VLAN
  • 连接new服务器注意事项
  • Java核心类库深度解析与实战:从字符串处理到计算器开发
  • 外网如何连接内网中的mysql数据库服务?跨网直接访问操作,不用公网IP
  • 人机协作系列(四)AI编程的下一个范式革命——看Factory AI如何重构软件工程?
  • 力扣——1071. 字符串的最大公因子
  • 解密AWS VPC路由表:显式关联与隐式关联,谁决定了网络出口?
  • 深入剖析Java并发基石:AQS原理与实战
  • java 并发面试题2
  • 【Java篇】IntelliJ IDEA 安装与基础配置指南
  • Linux操作系统从入门到实战(十)Linux开发工具(下)make/Makefile的推导过程与扩展语法
  • 大模型在1型糖尿病肾病V期预测及治疗方案制定中的应用研究
  • 快速了解 HTTPS
  • MyBatis Plus功能增强全解析:从手写SQL到优雅开发的进阶指南
  • 16、鸿蒙Harmony Next开发:组件扩展
  • KeilMDK5如何生成.bin文件
  • 项目进度跨地域团队协作困难,如何统一进度安排
  • PHP语法高级篇(三):Cookie与会话
  • Redis中的红锁
  • ADC采集、缓存
  • Axios 完整功能介绍和完整示例演示
  • 映美打印机-URL页面打印
  • Spring MVC 执行流程详解:一次请求经历了什么?