您的位置:首页 > Web前端

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

2014-08-09 12:53 363 查看
题目链接:点击打开链接

打表后发现规律,只有n%4==0时输出4否则输出0

代码:

#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
char c[1000000];
int main(){
    while(cin>>c){
        int len=strlen(c);
        int n;
        if(len<=1){
            n=c[len-1]-'0';
        }
        else{
            n=(c[len-2]-'0')*10+(c[len-1]-'0');
        }
        if(n%4)
                cout<<0<<endl;
        else
                cout<<4<<endl;
        memset(c,0,sizeof(c));
    }
    return 0;
}

//打表代码
/*long long pow(int i,int j){
    long long res=1;
    for(int k=1;k<=j;k++){
            res*=i;
            res%=5;

    }
    return res;
}

int main(){
    for(int i=1;i<=100;i++){
            cout<<i<<" "<<(pow(1,i)+pow(2,i)+pow(3,i)+pow(4,i))%5<<endl;
    }
}*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: