湖南工業大學創新實驗室2015年新生賽(一)1002(重開),湖南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。
Input
多組輸入,每組輸入兩個整數q和p(1<=q<=10,1<=p<=9)
Output
對於每一組數據首先輸入一個case #: #代表第幾組數據
然後輸出一個整數a,代表結果
Sample Input
1 1
2 2
3 3
Sample Output
case 1:1
case 2:4
case 3:27
Author
ikids
沒什麼好說的,就是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;
}