当前位置:网站首页>High efficiency exponentiation
High efficiency exponentiation
2022-06-27 13:29:00 【fitpolo】
#include <stdio.h>
long int pow(long int x,unsigned int n)
{
if (n==0)
{
printf("x:%ld-n==0\n",x);
return 1;
} else if (n==1)
{
printf("x:%ld-n==1\n",x);
return x;
} else
{
printf("x:%ld-n:%d\n",x,n);
if (n%2==0)
{
return pow(x*x,n/2);
}else
{
return pow(x*x,n/2)*x;
}
}
}
int main(int argc, char *argv[])
{
printf("pow(2,10):%ld\n",pow(2,10));
printf("pow(2,8):%ld\n",pow(2,8));
printf("%ld\n",2*2*2*2*2*2*2*2*2*2);
return 0;
}
Running results
边栏推荐
- 【第27天】给定一个整数 n ,打印出1到n的全排列 | 全排列模板
- [weekly replay] the 81st biweekly match of leetcode
- 面试官:Redis的共享对象池了解吗?
- awk 简明教程
- 如何使用200行代码实现Scala的对象转换器
- 手把手教你搭一个永久运行的个人服务器!
- Full explanation of ThreadLocal source code (threadlocalmap)
- TCP 流控问题两则
- Tiktok practice ~ public / private short video interchange
- Stack calculation (whether the order of entering and leaving the stack is legal) - Code
猜你喜欢
[tcaplusdb knowledge base] Introduction to tcaplusdb tcapulogmgr tool (I)
万物互联时代到来,锐捷发布场景化无线零漫游方案
[acwing] explanation of the 57th weekly competition
硬件开发笔记(七): 硬件开发基本流程,制作一个USB转RS232的模块(六):创建0603封装并关联原理图元器件
How to choose LAN instant messaging software
手把手教你搭一个永久运行的个人服务器!
After the deployment is created, the pod problem handling cannot be created
阿胖的操作记录
[weekly replay] the 81st biweekly match of leetcode
快讯:华为启动鸿蒙开发者大赛;腾讯会议发布“万室如意”计划
随机推荐
#yyds干货盘点# 解决剑指offer:剪绳子(进阶版)
Today's sleep quality record 78 points
每日刷题记录 (六)
Embedded development: embedded foundation callback function
再懂已是曲中人
清楚的自我定位
基于SSM实现招聘网站
scrapy
How to modify a node_ Files in modules
【动态规划】—— 背包问题
Openfeign service interface call
AGCO AI frontier promotion (6.27)
mysql 锁机制与四种隔离级别
【TcaplusDB知识库】TcaplusDB-tcapsvrmgr工具介绍(三)
MySQL locking mechanism and four isolation levels
Good luck today
ZABBIX supports nail alarm
Explore tidb lightning source code to solve the found bugs
【Acwing】第57场周赛 题解
How to download pictures with hyperlinks