An Excursion In Mathematics
Tag(s):

Math, Medium-Hard, Modular arithmetic

Problem
Editorial
Analytics

As Brutus betrayed Caesar he is planning to attack Brutus. But he knows Brutus cannot be defeated easily so he plans to use the excalibur sword. But there is one problem. To activate the sword he needs to solve the problem written on the sword. Can you help Caesar activate the sword by solving this problem??

Given the values of A($X^2+Y^2+Z^2$), B($X^4+Y^4+Z^4$), C($X^5+Y^5+Z^5$). Calculate the value of sum of values of $X^i+Y^i+Z^i$ where i goes from L to R modulo 1e9+7.

$Input :$

First line of the Input contains an integer T denoting the number of testcases. Each testcase contains two lines. The first line contains 3 integers A, B and C. The next line contains 2 integers L and R

$Output :$

print a single integer denoting the summation.

$Constraints$ :

$1 \le X,Y,Z \le 3000$

$1 \le T \le 10^3$

$1 \le L \le R \le 10^{18}$

Problem setter : Sheldon Tauro

SAMPLE INPUT
1
14 98 276
2 5
SAMPLE OUTPUT
424
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1, Swift, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...

Contributor

Challenge Name

Codemania 2.0

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Dynamic Programming
• Data Structures > Arrays
• Algorithms > Dynamic Programming
• Algorithms > Graphs
• Basic Programming > Input/Output
• Data Structures > Disjoint Data Structures
• Basic Programming > Implementation