问题描述:
给定一个整数n (n≥0),用以b为基数的k位数字表示。
n = a1⋅bk a2⋅bk−−1 + 2 +…ak−1⋅b +正义与发展党。
例如,如果b=17,k=3 and a=[11,15,7] ,n = 11⋅172 + 15⋅17 + 7 = 3179 + 255 + 7 = 3441。
确定n是偶数还是奇数。
输入
第一行包含两个整数b和k(2≤b≤100,1≤k≤105)——数字的基数和位数。
第二行包含k个整数a1,a2,…,ak(0≤ai<b) - n的位数。
n的表示形式不包含不必要的前导零。也就是说,只有k=1时a1才等于0。
输出
如果n是偶数,则打印“even”,否则打印“odd”。
您可以在任何情况下打印每个字母(大写或小写)。
input
13 3
3 2 7
output
even
input
10 9
1 2 3 4 5 6 7 8 9
output
odd
input
99 5
32 92 85 74 4
output
odd
input
2 2
1 0
output
even
分析:
奇数乘奇数=偶数
偶数乘任何=偶数
(如果b是偶数,只需要判断0次幂的情况就可以了)
代码:
#include<iostream>
#include<cstdio>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int inn=0x80808080;
using namespace std;
int main(){
int n,m;
int T=1;
//T=100;
while(T--){
cin>>n>>m;
int ans=0;
int t;
for(int i=m-1;i>=0;i--){
cin>>t;
if(n%2==1||i==0){//0次幂为1所以也要判断
ans=(ans+t%2)%2;
// cout<<ans<<endl;
}
}
cout<<(ans%2?"odd":"even")<<endl;
}
return 0;
}