首页 > 其他 > 详细

【Codeforces Global Round 1 A】Parity

时间:2019-02-08 10:08:57      阅读:204      评论:0      收藏:0      [点我收藏+]

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


给你一个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());
        }
    }
}

【Codeforces Global Round 1 A】Parity

原文:https://www.cnblogs.com/AWCXV/p/10355873.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!