Codeforces Round #260 (Div. 2)B. Fedya and Maths
and Codeforces div round
2023-09-11 14:14:10 时间
让求出 (1^n + 2^n + 3^n + 4^n )mod 5 的结果,而n最大能够有10^5位数。仅仅能用字符串来存,将取模分开得到
1^n mod 5 = 1 ;
2^n mod 5 = 随着n从0開始,结果为 1 2 4 3 1 2 4 3 1 2 4 3 。。
。。以1 2 4 3 循环
3^n mod 5 = 随着n从0開始。结果为 1 3 4 2 1 3 4 2 1 3 4 2.。
。
。。以1 3 4 2 循环
4^n mod 5 = 。。
。。结果为 1 4 1 4 1 4 以1 4 循环
求给出的n是奇数还是偶数,方法推断最后一位奇数偶数。
再求解n mod 4 。方法求出最后两位的对4取模的值
#include <cstdio> #include <cstring> char str[110000] ; int main() { int ans = 1 , l , i , k ; scanf("%s", str); l = strlen(str); if( (str[l-1]-'0')%2 ) ans += 4 ; else ans += 1 ; if( l-1 != -1 ) k = ( str[l-1]-'0' ); if( l-2 != -1 ) k = k + (str[l-2]-'0')*10 ; if( k%4 == 0 ) ans += 2 ; else if( k%4==1 ) ans += 5 ; else if( k%4 ==2 ) ans += 8 ; else ans += 5 ; printf("%d\n", ans%5); return 0; }
相关文章
- Firefox vulnerable process has been exploited and is running
- HDOJ 5418 Victor and World 状压DP
- Codeforces Round #837 (Div. 2) C. Hossam and Trainees
- CodeForces 362E Petya and Pipes
- Windows: create shortcut and autorun program
- android listview and scrollview
- 安装SSL证书 and 根域名跳转www域名
- CodeForces 916B Jamie and Binary Sequence (changed after round) (贪心)
- CodeForces 754C Vladik and chat (DP+暴力)
- CodeForces 548A Mike and Fax (回文,水题)
- UVaLive 7500 Boxes and Balls (数学)
- CodeForces 342C Cupboard and Balloons (几何问题)
- CS395-T: Robot Learning from Demonstration and Interaction
- Csharp: Listview convert Datatable and ListView.Group count
- Sql Server 2012 分页方法分析(offset and fetch)
- 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)
- 【CodeForces 504A】Misha and Forest
- 【CodeForces 621A】Wet Shark and Odd and Even
- Codeforces Round #226 (Div. 2)--A Bear and Raspberry
- 【打CF,学算法——二星级】Codeforces Round #312 (Div. 2) A Lala Land and Apple Trees
- A. Kyoya and Photobooks(Codeforces Round #309 (Div. 2))
- 【codeforces】Codeforces Round #277 (Div. 2) 解读
- Codeforces Round #243 (Div. 1)——Sereja and Two Sequences
- ARM Compiler for C and C++ in Linux
- 【bzoj1941】[Sdoi2010]Hide and Seek KD-tree