版权声明:本文为博主原创文章,未经博主同意不得转载。 https://blog.csdn.net/u013497151/article/details/27633731

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std; int pow(int x, int n)
{
int result = 1;
while (n > 0)
{
if (n % 2==1)
result *= x;
x *= x;
n /=2 ;
}
return result;
} int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int s = pow(n,m);
printf("%d\n",s);
}
return 0;
}

高速求幂 POW优化的更多相关文章

  1. 高速幂 POW优化

    #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h&g ...

  2. 求幂pow()

    pow(x, n)  求x的n次方. 最简单的方法便是计算n个x相乘 public static double pow(double x, int n) { if (n == 0) return 1; ...

  3. (十进制高速幂+矩阵优化)BZOJ 3240 3240: [Noi2013]矩阵游戏

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=3240 3240: [Noi2013]矩阵游戏 Time Limit: 10 Sec  M ...

  4. [leetcode]50. Pow(x, n)求幂

    Implement pow(x, n), which calculates x raised to the power n (xn). Example 1: Input: 2.00000, 10 Ou ...

  5. 快速求幂(Quick Exponentiation)

    接触ACM没几天,向各路大神求教,听说ACM主要是研究算法,所以便开始了苦逼的算法学习之路.话不多说,RT所示,学习快速求幂. 在头文件<math.h>或是<cmath>中,d ...

  6. NYOJ--102--次方求模(快速求幂取模)

    次方求模 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 求a的b次方对c取余的值   输入 第一行输入一个整数n表示测试数据的组数(n<100)每组测试只有一 ...

  7. 求幂运算、多项式乘法及Horner法则的应用

    一,两种不同的求幂运算 求解x^n(x 的 n 次方) ①使用递归,代码如下: private static long pow(int x, int n){ if(n == 0) return 1; ...

  8. 二分求幂,快速求解a的b次幂

    一个引子 如何求得a的b次幂呢,那还不简单,一个for循环就可以实现! void main(void) { int a, b; ; cin >> a >> b; ; i < ...

  9. ES7学习笔记——Array.prototype.includes和求幂运算符**

    一直以来,在前端开发时使用的基本都是ES5,以及少量的ES6.3月份换工作面试时,发现一些比较大的公司,对ES6比较重视,阿里的面试官直接问ES7和ES8,对于从未接触过人来说,完全是灾难.由此也显现 ...

随机推荐

  1. ajaxfileupload 上传使用demo

    1.添加js引用 <script src="JS/jquery-1.4.2.min.js" type="text/javascript"></ ...

  2. linux平台进行c语言源码安装

    安装c源程序的步骤: 1. ./configure --prefix 执行编译检测 指定安装路径 2. make 编译 3. sudo make install 编译后安装 前两步可以合成一步(mak ...

  3. PAT甲级——A1045 Favorite Color Stripe

    Eva is trying to make her own color stripe out of a given one. She would like to keep only her favor ...

  4. VC++ ComBox下拉菜单看不到值

    在使用ComBox的时候,我是预先在属性页里面添加了数据的.但是在运行程序是发现,点击下拉时,一个值都看不到! 如图: 在这:http://blog.csdn.net/nma_123456/artic ...

  5. 2019-7-9-Roslyn-如何在-Target-引用-xaml-防止文件没有编译

    title author date CreateTime categories Roslyn 如何在 Target 引用 xaml 防止文件没有编译 lindexi 2019-07-09 17:16: ...

  6. 阿里云应用高可用服务 AHAS 流控降级实现 SQL 自动防护功能

    在影响系统稳定性的各种因素中,慢 SQL 是相对比较致命的,可能会导致 CPU.LOAD 异常.系统资源耗尽.线上生产环境出现慢 SQL 往往有很多原因: 硬件问题.如网络速度慢,内存不足,I/O 吞 ...

  7. LUOGU P3024 [USACO11OPEN]奶牛跳棋Cow Checkers

    题目描述 One day, Bessie decides to challenge Farmer John to a game of ‘Cow Checkers’. The game is playe ...

  8. TZ_06_SpringMVC_常用注解

    1. @Controller@RequestMapping(path = "/user")//一级目录 public class FormSubmit { @RequestMapp ...

  9. laravel--laravel的重定向类Redirector

    laravel的重定向类Redirector 在laravel5中,重定向类可以直接通过redirect()方法直接获取,不需要声明,有几个常用的方法: redirect() -> to( “重 ...

  10. 通过Struts2Web应用框架深入理解MVC

    Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet. 一.用法简介: 1.Eclipse新建Dynamic Web Project, 项目名:Struts2Pro ...