寒假訓練數論B

2021-10-02 06:55:24 字數 1241 閱讀 7083

題目

fedya studies in a gymnasium. fedya』s maths hometask is to calculate the following expression:

(1^n  +  2^n + 3^n + 4^n) mod 5

for given value of n. fedya managed to complete the task. can you? note that given number n can be extremely large (e.g. it can exceed any integer type of your programming language).

input

the single line contains a single integer n (0 ≤ n ≤ 10105). the number doesn』t contain any leading zeroes.

output

print the value of the expression without leading zeros.

題目大意

給出乙個數n,求(1^n  +  2^n + 3^n + 4^n) mod 5的值。

解題思路

先把1^n , 2^n, 3^n, 4^n的規律找出來。

然後再找(1^n  +  2^n + 3^n + 4^n) mod 5的規律。

規律當n為4的倍數時,輸出4,其餘情況輸出0.

判斷乙個數是否為4的倍數(n很大)

法一 n%2為偶數

法二 判斷n(n>=10)的最後兩位是否為4的倍數,加上n<10 的特判

**

#include

#include

#include

using

namespace std;

string st;

intmain()

if(st[st.

size()

-1]%

2!=0)

printf

("0\n");

else

num=num*

10+st[st.

size()

-1]-

48;num/=2

;if(num%2==

0)printf

("4\n");

else

printf

("0\n");

}}

2021寒假訓練

之前都沒有記錄,這些是div2的 二分套二分板子,值得記錄 教訓 1 scanf eof 2 二分邊界!include include include include include include include include include include include include in...

2016寒假訓練 搜尋

一開始做這個題目還是覺的挺煩的,主要是要加個四個變數,然後比較,比較起來還比較麻煩。繞口令,呵呵 首先,不需要找到的次序,而且m 20,所以不會有爆棧的風險。然後就是怎麼去解決的問題,因為所有的木頭都是整數,所以我們考慮這個問題,所以我們可以預見的是,一旦總和 4不為0的話,則一定是不可能。下面就是...

寒假訓練2 總結

1 hdu 4810 wall painting 組合數 二進位制拆分 2 hdu 5573 binary tree 二進位制思維題 3 hdu 5501 the highest mark 揹包 貪心 4 hdu 5493 queue 樹狀陣列 二分查詢 5 hdu 3639 hawk and ch...