【Codeforces Global Round 1 A】Parity

【链接】 我是链接,点我呀:)
【题意】

给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数

【题解】

模拟一下转换的过程,加乘的时候都记得对2取余就好

【代码】

import java.io.*;
import java.util.*;

public class Main {
	
	static int N = (int)1e5;
	static InputReader in;
	static PrintWriter out;
	static int b,k;
	static int a[];
		
	public static void main(String[] args) throws IOException{
		in = new InputReader();
		out = new PrintWriter(System.out);
		
		//code start from here
		a = new int[N+10];
		b = in.nextInt();k = in.nextInt();
		for (int i = 1;i <= k;i++) a[i] = in.nextInt();
		int now = 1;
		long n = 0;
		for (int i = k;i >= 1;i--) {
			n = (n + a[i]*now)%2;
			now = (now * b)%2;
		}
		if (n%2==1) {
			out.println("odd");
		}else {
			out.println("even");
			
		}
		out.close();
	}

	static class InputReader{
		public BufferedReader br;
		public StringTokenizer tokenizer;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
		}
		
		public String next(){
			while (tokenizer==null || !tokenizer.hasMoreTokens()) {
				try {
				tokenizer = new StringTokenizer(br.readLine());
				}catch(IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}
posted @ 2019-02-08 08:31  AWCXV  阅读(204)  评论(0编辑  收藏  举报