F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Function

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 226    Accepted Submission(s): 101


Problem Description
There is a function $ f(n) = (a+\sqrt{b})^n + (a-\sqrt{b})^n $. a and b are integers $(1 \leq a,b \leq 1,000,000)$.
Maybe the function looks complex but it is actually an integer.The question is to calculate $ f(x^y)$.The answer can be
very large,so just output the answer mod $1,000,000,007$.
 

Input
There are multiple test cases. The first line of input contains an integer $T (1\leq T\leq 200)$ indicating the number of test cases. For each test case:

One line contains four integers $a,b$ $\ (1 \leq a,b \leq 1,000,000)$, $\ x(1\leq x \leq 50), y(1\leq y \leq 10^{18})$.
 

Output
For each test case, output one integer.
 

Sample Input
3 3 5 1 1 3 5 2 1 1 1 49 99999
 

Sample Output
6 28 160106184
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 13:12:43, Gzip enabled