「ABC221」A - Seismic magnitude scales 題解
A - Seismic magnitude scales
Time Limit: \(2\; sec\) / Memory Limit: \(1024\; MB\)
Score : \(100\; points\)
Problem Statement|題目描述
-
The magnitude of an earthquake is a logarithmic scale of the energy released by the earthquake. It is known that each time the magnitude increases by \(1\), the amount of energy gets multiplied by approximately \(32\)
-
地震的震級是地震釋放能量的對數尺度。已知震級每增加 \(1\) ,能量就會變為原來的大約 \(32\) 倍。
-
Here, we assume that the amount of energy gets multiplied by exactly \(32\) each time the magnitude increases by \(1\). In this case, how many times is the amount of energy of a magnitude \(A\) earthquake as much as that of a magnitude \(B\)
-
在本題中,我們假設每次震級增加 \(1\) 時,能量正好乘以 \(32\) 。在這種情況下, \(A\) 地震的能量是 \(B\) 級地震能量的多少倍?
Constraints|資料範圍
- \(3\leq B\leq A\leq 9\)
\(A\) and \(B\) are integers. - \(3\leq B\leq A\leq 9\)
- \(A\) 和 \(B\) 均為整數。
Input|輸入
-
Input is given from Standard Input in the following format:
A B
-
輸入為以下格式的標準輸入:
A B
Output|輸出
-
Print the answer as an integer.
-
輸出一個整數答案。
Sample Input 1 |樣例輸入 1
6 4
Sample Output 1 |樣例輸出 1
1024
- \(6\) is \(2\) greater than \(4\), so a magnitude \(6\) earthquake has \(32\times 32=1024\) times as much energy as a magnitude \(4\) earthquake has.
- \(6\) 級地震的能量是 \(4\)級地震的 \(32\times 32=1024\) 倍。
Sample Input 2 |樣例輸入 2
5 5
Sample Output 2 |樣例輸出 2
1
- Earthquakes with the same magnitude have the same amount of energy.
- 相同震級的地震具有相同的能量。
分析
作為一個謹慎的人,我終究還是開了\(long\;long\),又用了快速冪。
AC程式碼奉上
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll power(ll a,ll b){
if(!b)return 1;
ll ans=1;
while(b){
if(b&1)ans=ans*a;
b>>=1;
a*=a;
}
return ans;
}
int main(){
freopen("magnitude.in","r",stdin);
freopen("magnitude.out","w",stdout);
int a,b;
cin>>a>>b;
cout<<power(32,a-b);
return 0;
}