Codeforces Round #260 (Div. 2)B. Fedya and Maths

先用模拟的方法找出规律,发现答案是以 0 0 0 4 为循环。

由于输入的数巨大,用字符串接收数据,然后转化为4进制,在判断末尾是否为零。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>

using namespace std;
const int maxn = 100005;
char num[maxn];
int n;
int mpow(int x,int y){
    int ans = 1;
    for(;y;y>>=1){
        if(y&1){
            ans *= x;
            ans %= 5;
        }
        x *= x;
        x %= 5;
    }
    return ans;
}

int main(){
    /*int n;//找规律 (以0 0 0 4循环)
    for(n = 1;n < 500;n++){
        int ans = 0;
        for(int i = 1;i <= 4;i++){
            ans += mpow(i,n);
            ans %= 5;
        }
        printf("%d  ",(ans%5+5)%5);
        if(n%4 == 0)
            printf("\n");
    }*/
    while(~scanf("%s",num)){//输入的数很大用字符串接收
        int len = (int)strlen(num);
        for(int i = 0;i < len-1;i++){//将其转化为4进制判断末尾,判断最后一位是否为零
            int temp = (num[i] - '0')*10;
            temp %= 4;
            num[i+1] += temp;
        }
        //printf("%d",num[len-1]);
        if(num[len-1]%4 == 0)
            printf("4\n");
        else
            printf("0\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值