Codeforces Global Round 1 A. Parity
程序员文章站
2022-07-15 09:39:56
...
Codeforces Global Round 1 A. Parity
题目链接 http://codeforces.com/contest/1110/problem/A
题目大意:输入两个数字 n,k,包括一个数组a,由公式 n=a1⋅bk−1+a2⋅bk−2+…ak−1⋅b+ak,计算结果,如果结果是偶数 怎输出 “even”,否则输出"odd"
思路:for循环叠加结束!代码如下
#include <iostream>//http://codeforces.com/contest/1110/problem/A
#include <cmath>
using namespace std;
#define LL long long
int s[100005];
LL poww(LL a,LL b) //计算a的b次方函数
{
LL ans=1;
while(b)
{
if(b&1)
ans*=a;
a*=a;
b>>=1; //位运算符 b>>1=b/2;
}
return ans;
}
int main()
{
int b,k;
cin>>b>>k;
LL sum=0;
for(int i=0;i<k;i++)
{
cin>>s[i];
// cout<<s[i]<<endl;
sum+=s[i]*poww(b,k-i-1);
// cout<<sum<<endl;
}
//cout<<sum<<endl;
if(sum&1) //判断sum是否为奇数
cout<<"odd"<<endl;
else
cout<<"even"<<endl;
return 0;
}
推荐阅读
-
Codeforces Global Round 9-C. Element Extermination
-
Codeforces Round #655 (Div. 2) A. Omkar and Completion
-
Codeforces Global Round 9(A~D题解)
-
Codeforces Round #659 (Div. 2) A. Common Prefixes(字符串,思维)
-
Codeforces Round #686 (Div. 3) A. Special Permutation
-
Codeforces A. Sign Flipping (思维 / 构造) (Global Round 9)
-
A. Add Odd or Subtract Even(思维题) Codeforces Round #624 (Div. 3)
-
Codeforces Round #443 (Div. 1) CodeForces - 878 A
-
【Codeforces Global Round 7】A. Bad Ugly Numbers 题解
-
Codeforces Global Round 7 A. Bad Ugly Numbers