ACM_Congruence + Violence to find the law

Little Light's Sadness

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

Kai Shen: I respect the original intention of the author, I will add whatever you come up with. So Xiaoguang played a water quiz (that is, this one), but during the game, he couldn't AC with his own standard distance, and finally he could only play the watch embarrassingly! ! for Mao? ! Please take a look at this question. In order to relieve Xiaoguang's embarrassment, he decided not to tell you the sample input and output, what? ! No input and output? Yes, it is such a thief!

Input:

Multiple sets of data, input n, find (1^n+2^n+3^n+4^n) mod 5, where n is in the range [10^5, 10^(10^5)], the number may have a leading 0 .

Output:

Of course it's the result~

Sample Input:

not for you

Sample Output:

Just don't give you 
the idea of ​​​​solving the problem: the meaning of the title is very simple, and it has been prompted to find the law, so (quick power) violent enumeration search, and found that if it is a multiple of 4, the calculation result is 4, otherwise it is 0. The number of digits in the interval number of the red part n is 5 digits to 100,000 digits, so the length of the string can be opened by 10^5+5. Note that the read string may have leading 0s, so remove the leading '0'.
Test code:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 LL mod_pow(LL base,LL n,LL mod){//快速幂
 5     LL res=1;
 6     while(n){
 7         if(n&1)res=res*base%mod;
 8         base=base*base%mod;
 9         n>>=1;
10     }
11     return res;
12 }
13 int main(){
14     LL sum=0;//测试
15     for(int i=100000;i<1000000;++i){
16         sum=(mod_pow(2,i,5)+mod_pow(3,i,5)+mod_pow(4,i,5)+1)%5;
17         cout<<i<<' '<<sum<<endl;
18         if(i%4==0 )cout<<i<< " Yes " << endl;
 19      }
 20      return  0 ;
 21 }
AC code:
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char s[100005];
 4 int main(){
 5     while(cin>>s){
 6         int sum=0,j=0;
 7         while(s[j]=='0')++j;//去掉前导0
 8         for(int i=j;i<(int)strlen(s);++i)
 9             sum=(sum*10+(s[i]-'0')% 4 )% 4 ; // Congruence equation 
10          if (sum% 4 )cout<< ' 0 ' <<endl; // Law 
11          else cout<< ' 4 ' << endl;
 12      }
 13      return  0 ;
 14 }
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325273805&siteId=291194637
law