Cf #260 B. Fedya and maths

Source: Internet
Author: User

Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expression:

(1 N? +? 2 N? +? 3 N? +? 4 N) MoD5

For given valueN. Fedya managed to complete the task. Can you? Note that given numberNCan be extremely large (e.g. It can exceed any integer type of your programming language ).

Input

The single line contains a single integerN(0? ≤?N? ≤? 10105). The number doesn' t contain any leading zeroes.

Output

Print the value of the expression without leading zeros.

Sample test (s) Input
4
Output
4
Input
124356983594583453458888889
Output
0
Note

OperationX mod yMeans taking remainder after DivisionXByY.

Note to the first sample:


He does not understand the Fermat theorem. After the table is typed, 4 is output when n % 4 = 0,
The rest outputs 0, but n data is too big. We know that the number above 100 can be broken down into 100 * X + Y. You only need to consider y, that is, you only need to consider the last two. This is easy to handle. Read the string to get the last two modulo operations.
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<limits.h>#include<cmath>using namespace std;const int maxn=1e6;char s[maxn];int main(){    while(~scanf("%s",s))    {        int len=strlen(s);        int sum=0;        sum+=s[len-1]-'0'+(s[len-2]-'0')*10;        if(sum%4==0)            cout<<4<<endl;        else            cout<<0<<endl;    }    return 0;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.