Easy Math > Modular Arithmetic

The story is about one of the fastest racing video game Need for Speed Most Wanted where the gamer needs to defeat the blacklist members to prove the gamer him/herself best.<br> A Hype is moving around in the air of NFS city from some days ago – <br> <blockquote>**NFSMW top black List member Gazor can be defeated if you have the boosters installed in your car.**</blockquote> You are the clever one. And you own some of the boosters.<br> The boosters are with the initial power **1, 2, … …, P**. You can raise the power level of boosters up to a certain exponent level ( **N** ). You have decided to raise the power level of boosters, sum up all of the powers after raising and apply to your vehicle’s engine. But the vehicle has a weird power display window. It shows the **applied power modulo 5**. You have to find out the number that will be shown on the display? Interesting Huh!! Input: ------ Input starts with an integer **T** which denotes the number of test cases.<br> Each of the next **T** lines will contain two integers **P** and **N**, where **P** denotes the boosters you owned with initial power **( 1, 2 . . . P )** and **N** denotes the level of power you want to raise. Constraints ------- 1<= **T** <= 100000<br> 1<= **P** <= 9<br> 0<= **N** <= 10^15<br> Output: ------- For each test case, you need to print **(1^N + 2^N + …. + P^N)** modulo **5**. Sample Input ------------ 2 4 0 7 1 Sample Output ------------- 4 3 <b>Explanation</b><br> <ul> <li>For the first test case, ( 1^0 + 2^0 + 3^0 + 4^0)%5 = 4%5 = 4</li> <li>For the second test case, ( 1^1 + 2^1 + 3^1 + 4^1 + 5^1 + 6^1 + 7^1)%5 = (1+2+3+4+5+6+7)%5 = 28%5 = 3.</li> </ul>

Avik Sarkar

Language |
Time Limit (seconds) |

C | 1.00 |

C++ | 1.00 |

C++14 | 1.00 |

C# | 1.00 |

Go | 2.00 |

Java | 1.00 |

JavaScript | 2.00 |

Objective-C | 2.00 |

Perl | 2.00 |

PHP | 2.00 |

Python | 1.00 |

Python3 | 1.00 |

Ruby | 2.00 |

VB.Net | 2.00 |

Solve/Submission

# | User | Language | Timing |
---|---|---|---|

01 | ssavi | Cpp | 0.03s |

02 | pulak_ict_mbstu | Cpp | 0.03s |

03 | feodorv | C | 0.03s |

04 | ss1230 | Cpp14 | 0.03s |

05 | _GhOstMan_ | Cpp | 0.04s |

06 | tariqiitju | Cpp14 | 0.04s |

07 | yasirnabil534 | Cpp | 0.04s |

08 | Dragon_Curve | Cpp | 0.04s |

09 | Bappy | Cpp14 | 0.04s |

10 | mhiceiuk | Cpp | 0.06s |

11 | kakarotto | Cpp | 0.07s |

12 | t0whid | Cpp | 0.08s |

13 | Silent_Warrior | Cpp | 0.13s |

14 | Riad_IIT7 | Cpp | 0.17s |

15 | milon019 | Cpp | 0.17s |

16 | rayhan50001 | Cpp14 | 0.19s |

17 | skmonir | Cpp | 0.19s |

18 | fayedanik | Cpp | 0.20s |

19 | mohibur | Cpp14 | 0.20s |

20 | S_Saqib | Cpp | 0.29s |

21 | wajiul | Cpp | 0.31s |

22 | SAIF_IIT8_JU | C | 0.33s |

23 | Chayti_Saha98 | Cpp | 0.33s |

24 | Roll_no_152 | C | 0.34s |

25 | we7d | Cpp | 0.35s |

26 | maxhasan | Cpp | 0.35s |

27 | Rijoanul_Shanto | Cpp14 | 0.36s |

28 | MRITuhin | Cpp | 0.37s |

29 | Sakhawat_CoU | Cpp | 0.38s |

30 | deloar1 | Cpp | 0.39s |

31 | L1nK1n | Cpp | 0.39s |

32 | masba | Python | 0.40s |

33 | sparrow | C | 0.40s |

34 | Madhab | Cpp | 0.41s |

35 | prateepm | Cpp14 | 0.41s |

36 | sajjad_h | Cpp | 0.42s |

37 | prodipdatta7 | Cpp14 | 0.43s |

38 | Khayrul_34 | Cpp | 0.43s |

39 | asif04 | Cpp14 | 0.43s |

40 | loser_123 | Cpp | 0.43s |

41 | Abu_Bakar | Cpp | 0.44s |

42 | reasad | Cpp | 0.45s |

43 | duronto20 | Cpp | 0.45s |

44 | Limon_88 | Cpp | 0.46s |

45 | Raka143 | Cpp | 0.47s |

46 | joy25896 | Cpp | 0.48s |

47 | Zihad | Cpp | 0.49s |

48 | ashique111 | Cpp | 0.49s |

49 | Logic_Hunter | Cpp14 | 0.51s |

50 | hamza133913 | Cpp | 0.52s |

Copyright © 2015-2016 Dev Skill.

Feedback
#### Your feedback is our precious!

## Thank you for providing feedback! Our developers will be happy :)

## Sorry there was a problem when submitting the feedback. Please try again. :(