湖南工业大学创新实验室2015年新生赛(一)1002(重开)
工大第一美男子的回归故事
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 39 Accepted Submission(s) : 23
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
工大第一美男子月神从阿里回来了,ACM的小伙伴们自然是十分的开心!
当然,他们这么开心除了是想月神之外,也是想狠狠宰月神一顿。
月神毕竟是月神,财大气粗,除了请客之外,他还会解答小伙伴们的疑问。
但是,问题一来,就如同排山倒海,让月神应接不暇,所以,他想让你帮帮忙,代他回答这些问题。
对于每个整数q,代表问题,整数p,代表啪啪啪你要输出的是 a = q^p。
当然,他们这么开心除了是想月神之外,也是想狠狠宰月神一顿。
月神毕竟是月神,财大气粗,除了请客之外,他还会解答小伙伴们的疑问。
但是,问题一来,就如同排山倒海,让月神应接不暇,所以,他想让你帮帮忙,代他回答这些问题。
对于每个整数q,代表问题,整数p,代表啪啪啪你要输出的是 a = q^p。
Input
多组输入,每组输入两个整数q和p(1<=q<=10,1<=p<=9)
Output
对于每一组数据首先输入一个case #: #代表第几组数据
然后输出一个整数a,代表结果
然后输出一个整数a,代表结果
Sample Input
1 1 2 2 3 3
Sample Output
case 1:1 case 2:4 case 3:27
Author
没什么好说的,就是a = q^p罢了,实在怕超时可以用快速幂
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
using namespace std;
int pow(int x, int n)
{
int pw = 1;
while (n > 0)
{
if (n & 1) // n & 1 等价于 (n % 2) == 1
pw *= x;
x *= x;
n >>= 1; // n >>= 1 等价于 n /= 2
}
return pw;
}
int main()
{
int p,q;
int num=1;
while(cin>>p>>q)
{
printf("case %d:%d\n",num++,pow(p,q));
}
return 0;
}

浙公网安备 33010602011771号