Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long int ll;
ll exponent( ll base, ll power)
{
ll result=1;
ll temp=base;
while(power!=0)
{
if(power&1)
{
result=(result*temp)%MOD;
}
temp=(temp*temp)%MOD;
power=power>>1;
}
return result;
}
ll inverse(ll a)
{
ll val= MOD-2;
return exponent(a,val);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t,n,k,m;
cin>>t;
while(t--)
{
cin>>n>>k>>m;
ll count;
ll numerator=1,denominator=1;
if(m%2==0)
{
count=m/2;
numerator=exponent(n-1,count);
denominator=exponent(n,count);
numerator=(numerator*(n+k-1))%MOD;
denominator=(denominator*(n+k))%MOD;
}
else
{
count=(m+1)/2;
numerator=exponent(n-1,count);
denominator=exponent(n,count);
}
numerator=(denominator-numerator+MOD)%MOD;
denominator=inverse(denominator);
ll ans=(denominator*numerator)%MOD;
cout<<ans<<endl;
}
return 0;
}
M=10**9+7
dp={}
def MODmul(a,b):
return ((a%M)*(b%M))%M
def MODdiv(a,b):
return a*pow(b,M-2,M)%M
def MODdivFake(a,b):
return (a,b)
def MODadd(a,b):
return ((a%M)+(b%M))%M
def MODsub(a,b):
return ((a%M)-(b%M)+M)%M
def gcd(a,b):
if (a,b) in dp:return dp[(a,b)]
if a==0:
dp[(a,b)]=b
return b
dp[(a,b)]=gcd(b%a,a)
return dp[(a,b)]
'''
x,y=1,1
def gcdExtended(a, b, x, y):
global x,y
if a == 0 :
x = 0
y = 1
return b
x1 = 1
y1 = 1
gcd = gcdExtended(b%a, a, x1, y1)
x = y1 - (b/a) * x1
y = x1
return gcd
'''
def gm(c,r,k):
if c%2:
m=(c-1)//2
rm_1=pow(r-1,m,M)
rm=pow(r,m,M)
n1=MODmul(rm,(r+k))
n2=(rm_1*(1-r-k))
d=MODmul(rm,r+k)
return [MODadd(n1,n2),d]
m=c//2
rm=pow(r,m,M)
return [MODsub(rm,pow(r-1,m,M)),rm]
def fracAdd(n1,d1,n2,d2): #MOD NOT APPLIED
d1=d1
d2=d2
g=gcd(d1,d2)
lcm=((d1)*(d2/g))
n1=((n1)*(lcm//d1))%M
n2=((n2)*(lcm//d2))%M
n=(n1+n2)%M
return [int(n),int(lcm)]
def getFrac(n,k,c):
if n==1:return [1,1]
if c==1:return [1,n]
if n<=k:
if c==2:
return [2*n+k-1,n*(n+k)]
else:
r=(n+k)%k
if r==0:r=n
n1,d1=1,n
n2,d2=n-1,n
n3,d3=gm(c-1,r,k)
n2=MODmul(n2,n3)
d2=MODmul(d2,d3)
return fracAdd(n1,d1,n2,d2)
r=n%k
if r==1:return [1,1]
if r==0:r=k
return gm(c,r,k)
def ans(n,k,c):
n,d=getFrac(n,k,c)
g=gcd(n,d)
n,d=[n//g,d//g]
return MODdiv(n,d)
if __name__=="__main__":
for _ in range(int(input())):
n,k,c=[int(i) for i in input().split()]
print(ans(n,k,c))
'''
import cc3 as other
for n in range(1,51):
for k in range(1,51):
for c in range(1,51):
#print(n,k,c)
ans1=other.ans(n,k,c)
ans2=ans(n,k,c)
if ans1!=ans2:
print("input ",n,k,c)
print(ans1,ans2)
'''
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long int gcd(long long int a,long long int b);
long long int modInverse(long long int a,long long int m);
long long int power(long long int x,long long int y, long long int m);
int main()
{
long long int t,i,j,p,q,m,n,k,l,NIX,x,NI,NX;
scanf("%lld",&t);
for(i=0;i<t;i++)
{
scanf("%lld %lld %lld",&n,&k,&m);
if(n==1) { p=1; q=1; printf("1\n"); continue; }
if(m%2>0)
{
x=floor(m/2)+1;
NX=power(n,x,1000000007);
NIX=power(n-1,x,1000000007);
if(NX-NIX<0) { NX+=1000000007; }
p=(NX-NIX)%1000000007;
q=NX%1000000007;
}
if(m%2==0)
{
x=m/2;
NX=power(n,x,1000000007);
NIX=power(n-1,x,1000000007);
if(NX-NIX<0) { NX+=1000000007; }
p=(((NX-NIX)%1000000007*(n+k))%1000000007+NIX)%1000000007;
q=(NX*((n+k)%1000000007))%1000000007;
}
j=modInverse(q,1000000007)%1000000007;
if(NX-NIX<0){ printf("no");}
l=(p*j)%1000000007;
printf("%lld\n",l);
}
return 0;
}
long long int gcd(long long int a,long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
long long int modInverse(long long int a,long long int m)
{
long long int g = gcd(a, m);
if (g != 1)
printf("Inverse doesn't exist");
else
{
return power(a, m-2, m);
}
}
long long int power(long long int x,long long int y, long long int m)
{
if (y == 0)
return 1;
long long int p = power(x, y/2, m) % m;
p = (p * p) % m;
return (y%2 == 0)? p : (x * p) % m;
}
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
class Main
{
static class Chef implements Comparable<Chef> {
int age;
int rating;
Chef(int age,int rating) {
this.age = age;
this.rating = rating;
}
@Override
public int compareTo(Chef p) {
return this.age-p.age;
}
}
/*
class Pair
{
int f,s;
Pair( int f, int s)
{
this.f=f;
this.s=s;
}
}*/
static class Dish{
int id;
int time;
Dish(int a, int b){
this.id = a;
this.time = b;
}
}
static class compare implements Comparator<Dish>{
public int compare(Dish a, Dish b){
if(a.time!=b.time)return a.time - b.time;
else return a.id - b.id;
}
}
static class Pair {
char prefix;
int suffixId;
Pair(char prefix, int suffixId) {
this.prefix = prefix;
this.suffixId = suffixId;
}
@Override
public int hashCode() {
final int prime = 199;
int hash = 0;
hash = prime * prefix + hash;
hash = prime * suffixId + hash;
return hash;
}
@Override
public boolean equals(Object obj) {
if(obj instanceof Pair) {
Pair p2 = (Pair) obj;
return this.prefix == p2.prefix && this.suffixId == p2.suffixId;
}
return false;
}
}
static class Circle{
long x;
long y;
long r;
public Circle(long x, long y, long r) {
this.x = x;
this.y = y;
this.r = r;
}
}
static class Distance{
long shortest;
long largest;
}
/*static class pair implements Comparable<pair>
{
long x;
int y;
pair(long x,int y)
{
this.x=x;
this.y=y;
}
public int compareTo(pair o)
{
return (int)(x-o.x);
}
}
static class Pair
{
long x,y;
Pair(long x, long y)
{
this.x = x;
this.y = y;
}
}
static class PairComparator implements Comparator<Pair>
{
public long compare(Pair a, Pair b)
{
//if(a.x==b.x)
return a.y-b.y;
// return a.x-b.x;
}
}
static class Point {
public double x, y;
private static final int MAX = (int) 1e6 + 1;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public int hashCode() {
return (int)x * MAX + (int)y;
}
public boolean equals(Object ob) {
if(ob instanceof Point) {
Point other = (Point) ob;
return other.x == x && other.y == y;
}
return false;
}
public String toString() {
return "(" + x + ", " + y + ")";
}
}*/
/* static int days4=0;
static int all;
static long phi[]=new long[1000001];
static long ans[]=new long[1000001];
//static int tree[],sum[];
//public static long mod = 1000000007; public static long [][] tempMatrix;
public static long max = (long) Math.pow(10, 9) + 7;
static StringBuilder res = new StringBuilder();
//static Node tree[];
//static int a[];
// static long mod = 998244353;
public static int rootColor=0;
static int MX = (1<<18);
// static boolean primes[]=new boolean[10000001];*/
static double pi = 3.1415926535;
private static final int MAXN = 5000;
/* private static final int MOD = 1000_000_007;
private static Modular modular_nCr = new Modular(MOD);
private static Modular modular = new Modular(MOD);
private static final long[][] nCr = new long[MAXN+5][MAXN+5];
static int[] maxval = new int[1000000];
static int[] minval = new int[1000000];
private static long bruteAns = 1;
static double eps = 1e-7;
static {
nCr[0][0]=1;
for(int i=0;i<=MAXN;i++)
nCr[i][0]=1;
for(int i=1;i<=MAXN;i++){
for(int j=1;j<=i;j++){
nCr[i][j]=(nCr[i-1][j-1]+nCr[i-1][j])%MOD;
}
}
}*/
/*
static { nCr[0][0] = 1;
for (int i = 1; i < MAXN; i++) {
nCr[i][0] = 1;
for (int j = 1; j <= i; j++) {
nCr[i][j] = modular_nCr.add(nCr[i - 1][j - 1], nCr[i - 1][j]);
} }
}
static int arr[] , dp[][][];
// static int n ;
static int final_sum=0;
static int mod=1000000007;
static ArrayList<Integer> graph[];
static boolean vis[];
static int seive[]=new int[1000001];
static int primes[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
static int[] calcPower() {
int[] arr = new int[26];
for (int i = 0; i < 26; i++) {
arr[i] = (int) Math.pow(2, i);
}
return arr;
}
// static int p[] = new int[1000001], size[] = new int[1000001], n, m;
static int bits=32;
static class Trie
{
Trie tree[]=new Trie[2];
int val=0;
public Trie()
{
val=0;
tree[0]=null;tree[1]=null;
}
}
static Trie root;
static void insert(int xor)
{
Trie temp=root;
for(int i=bits-1;i>=0;i--)
{
int v = (xor & (1<<i)) >=1 ? 1 : 0;
if(temp.tree[v]==null)
temp.tree[v]=new Trie();
temp=temp.tree[v];
}
temp.val=xor;
}
static int query(int xor)
{
Trie temp=root;
for(int i=bits-1;i>=0;i--)
{
int v = (xor & (1<<i)) >=1 ? 1 : 0;
if(temp.tree[1-v]!=null)
temp=temp.tree[1-v];
else if(temp.tree[v]!=null)
temp=temp.tree[v];
}
return xor^temp.val;
}
public static int getBit(int n, int pos) {
return (n & (1 << pos)) == 0 ? 0 : 1;
}
private static int n, m, ci, cj;
private static char[][] g;
private static boolean[][] vs;
private static int[] v = new int[]{-1, 0, 1, 0};
private static int[] h = new int[]{0, 1, 0, -1};
private static char[] d = new char[]{'U', 'R', 'D', 'L'};
private static boolean v(int i, int j) {
return (i >= 0 && i < n && j >= 0 && j < m);
}
private static boolean pr(int i, int j) {
return g[i][j] == '*';
}
private static double dh, dl, dr, k;
static int zero = Integer.MAX_VALUE, one = Integer.MAX_VALUE;
static ArrayList<Long> leaf=new ArrayList<>();*/
static int mod=1000000007;
static int MX = 1000001;
static int pr[] = new int[MX];
static boolean cmp[] = new boolean[MX];
static int c = 0;
static void pre(){
for(int x = 2;x<MX;x++){
if(!cmp[x]){
pr[c++] = x;
for(int y = x+x; y<MX; y+=x){
cmp[y] = true;
}
}
}
}
// static final int MAXN = (int) 1e6;
static int spf[] = new int[MAXN];
static ArrayList<Integer> primes = new ArrayList<>();
static final int size = 1000001;
static final long MOD = 1000000007L;
static int n;
static int m;
static int a[] = new int[size];
static int dp[] = new int[size];
// static int arr[] = new int[size];
static int stops;
static int[] arr = new int[] {2,3,5,7,11,13,17,19,23,29};
public static List<Integer> g[];
public static long[] subLeaf;
public static long[] count;
public static void dfs(int node,int parent){
if(g[node].size()==1){
subLeaf[node]=1;
return;
}
long paths=0;
for(Integer i : g[node]){
if(i==parent){
continue;
}
dfs(i,node);
subLeaf[node]+=subLeaf[i];
count[node]+=(paths*subLeaf[i]);
paths+=subLeaf[i];
}
}
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
// FastReader in = new FastReader(System.in);
StringBuilder sb = new StringBuilder();
FastScanner in=new FastScanner();
// Scanner sc = new Scanner(System.in);
PrintWriter out=new PrintWriter(System.out);
HashMap<Character, Integer> h = new HashMap<Character, Integer>();
// TreeMap<Integer, Integer> h1 = new TreeMap<Integer, Integer>();
// HashMap<Integer, Integer> h2 = new HashMap<Integer, Integer>();
// HashSet<Point> s = new HashSet<Point>();
// HashSet<Double> s2 = new HashSet<Double>();
// HashSet<Double> s3 = new HashSet<Double>();
// HashSet<Character> h2 = new HashSet<Character>();
//long t= in.nextLong();
// long t = in.nextLong();
//DecimalFormat df = new DecimalFormat("#,###,##0.000000");
/* boolean prime[]=new boolean[10000000];
int p[]=new int[10000000];
int k=1;
Arrays.fill(prime, true);
prime[0]=false;
prime[1]=false;for(int i=2;i<10000000;i++)
{
if(!prime[i])
{
p[i]=p[i-1];
continue;
}
p[i]=k; k++;
for(long j=(long)i*i;j<10000000;j+=i)
prime[(int)j]=false;
}
// BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
/* int pri[]=new int[1000005];
int p=2;
List<Integer> list=new ArrayList<>();
while(p*p <=1000005)
{
if(pri[p]==0)
{
for(int i=p*2;i<=1000004;i=i+p)
{
pri[i]=1;
}
list.add(p);
}
p++;
}
//System.out.println(list);*/
int t = in.nextInt();
while(t-->0)
{
long N = in.nextLong();
long k = in.nextLong();
long m = in.nextLong();
long sum;
long mod = 1000000000 + 7;
long temp;
long size;
long ans;
if (m % 2 == 1)
size = (m+1) / 2 ;
else
size = m / 2;
temp = (power((N - 1), size) * power(N, (size * (mod - 2)))) % mod;
//System.out.println(temp);
ans = (1 - temp + mod) % mod;
if (m % 2 == 1)
sum = ans;
else
sum = (ans + (temp * power((N + k), (mod - 2))) % mod) % mod;
out.println(sum);
}
out.close();
}
static long power(long x, long y) {
long mod = 1000000000 + 7;
long res = 1;
while (y > 0) {
if(y%2==1)
res=(res*x)%mod;
x=(x*x)%mod;
y=y/2;
}
return res;
}
static boolean isSquare(int n)
{
if(Math.ceil((double)Math.sqrt(n))==Math.floor((double)Math.sqrt(n)))
return true;
return false;
}
public static long gcd(long a,long b,long n){
if(a==b){
return (power(a,n,mod)+power(b,n,mod))%mod;
}
long res=1l;
long num=a-b;
for(long i=1;i*i<=num;i++){
if(num%i==0){
long temp= (power(a,n,i)+ power(b,n,i))%i;
if(temp==0){
res=Math.max(res,i);
}
temp= (power(a,n,num/i) + power(b,n,num/i))%(num/i);
if(temp==0){
res=Math.max(res,num/i);
}
}
}
return res%mod;
}
public static long power(long a,long n,long d){
long res=1l;
while(n>0){
if(n%2==1){
res =((res%d)*(a%d))%d;
n--;
}else{
a=((a%d)*(a%d))%d;
n=n/2;
}
}
return res%mod;
}
/* static long power(long x,long y) {
long res=1;
x%=m;
while(y>0) {
if(y%2!=0)
res=(res*x)%m;
y=y>>1;
x=(x*x)%m;
}
return res;
}
*/
static long gcd(long a, long b)
{
if(b==0)
return a;
else
return gcd(b, a%b);
}
static long nextPower_2 ( long x, long y )
{
long count = 0 ;
while ( y < x )
{count ++ ;
y = y << 1 ;
}
return count ;
}
/*
static long power(long a, long b, long p)
{ long x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);
if (x >= p) x %= p;
}
y = (y * y); if (y >= p) y %= p;
b /= 2;}
return x;
}*/
public static class Modular {
private int MOD;
Modular(int MOD) {
this.MOD = MOD;
}
public long add(long a, long b) {
return (a + b) % MOD;
}
public long sub(long a, long b) {
return (a - b + MOD) % MOD;
}
public long mul(long a, long b) {
return (a * b) % MOD;
}
public long div(long a, long b) {
return mul(a, inverseEuler(b));
} public long power(long a, long b) {
long x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y);if (x >= MOD) x %= MOD;
}
y = (y * y);
if (y >= MOD) y %= MOD;
b /= 2;}
return x;
}
public long inverseEuler(long n) {
return power(n, MOD - 2);
}
}
static class FastReader {
byte[] buf = new byte[2048];
int index, total;
InputStream in;FastReader(InputStream is) {
in = is;
} int scan() throws IOException {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0) { return -1;
}
}
return buf[index++];
}
String next() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) {
sb.append((char) c);}
return sb.toString();
}String nextLine() throws IOException {
int c;for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c != 10 && c != 13; c = scan()) {
sb.append((char) c);
} return sb.toString();
}char nextChar() throws IOException {
int c;
for (c = scan(); c <= 32; c = scan()) ;
return (char) c;
} int nextInt() throws IOException {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan(); }
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}long nextLong() throws IOException {
int c;long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+') {
c = scan();
}
for (; c >= '0' && c <= '9'; c = scan()) {
val = (val << 3) + (val << 1) + (c & 15);
}
return neg ? -val : val;
}
}
static class FastScanner{
BufferedReader br;
StringTokenizer st;
public FastScanner(){br=new BufferedReader(new InputStreamReader(System.in));}
String nextToken(){
while(st==null||!st.hasMoreElements())
try{st=new StringTokenizer(br.readLine());}catch(Exception e){}
return st.nextToken();
}
int nextInt(){return Integer.parseInt(nextToken());}
long nextLong(){return Long.parseLong(nextToken());}
double nextDouble(){return Double.parseDouble(nextToken());}
}
}
import math
from fractions import Fraction
mod=pow(10,9)+7
for _ in range(int(input())):
N,K,M=map(int,input().split())
x=math.ceil(M/2)
g=pow(N,x,mod)
i=pow(N-1,x,mod)
if(M%2)==0:
g*=(N+K)
i*=(N+K-1)
P=Fraction(g-i,g).numerator
Q=Fraction(g-i,g).denominator
inverse=pow(Q,mod-2,mod)
print((P*inverse)%mod)
# your code goes here
from sys import stdin
from sys import stdout
mod=10**9+7
def computeGCD(x, y):
while(y):
x, y = y, x % y
return x
def solution():
for _ in range(int(stdin.readline())):
n,k,m=map(int,stdin.readline().split())
r=0
x , y=m/2, m%2
p, q=0, 0
# pqr()
#print ("YO2")
if y>0:
p=pow(n-1,x+1,mod)
q=pow(n,x+1,mod)
else:
p=pow(n-1,x,mod)
q=pow(n,x,mod)
r+=1
#pqr()
if(r==1):
p=(p*(n+k-1))%mod
q=(q*(n+k))%mod
#print("YO3")
p=(q-p+mod)%mod
z=computeGCD(p,q)
p=p/z
q=q/z
ans=((p%mod) * (pow(q,mod-2,mod)))%mod
#print ("YO")
stdout.write("%d\n"%ans)
#print(ans)
if __name__=='__main__':
solution()
using System;
using System.Numerics;
public class Test
{
public static void Main()
{
var t = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < t; i++)
{
var line = Console.ReadLine().Split(' ');
var n = Convert.ToInt32(line[0]);
var k = Convert.ToInt32(line[1]);
var m = Convert.ToInt32(line[2]);
Rational r, p;
r = new Rational(1) - new Rational(1, n);
p = new Rational(1, n) * (new Rational(1) - (r ^ ((m + (m % 2 == 1 ? 1 : 0)) / 2))) / (new Rational(1) - r);
if (m % 2 == 0)
{
p += (new Rational(1) - p) * new Rational(1, n + k);
}
Console.WriteLine("{0}", p.PQM());
}
}
}
public class Rational
{
private BigInteger _numerator = 0;
private BigInteger _denominator = 1;
static int m = 1000000007;
public Rational(BigInteger BigInteger_value)
{
set(BigInteger_value, 1);
}
public Rational(BigInteger new_numerator, BigInteger new_denominator)
{
set(new_numerator, new_denominator);
}
public void set(BigInteger new_numerator, BigInteger new_denominator)
{
if (new_denominator == 0)
{
throw new ArithmeticException("Denominator must not be 0");
}
_numerator = new_numerator % m;
_denominator = new_denominator % m;
_regularize();
}
private void _regularize()
{
BigInteger divisor = _denominator.Sign * BigInteger.GreatestCommonDivisor(_numerator, _denominator);
if (divisor == 0)
{
_numerator = 0;
_denominator = 1;
}
else
{
_numerator /= divisor;
_denominator /= divisor;
}
}
public static Rational operator +(Rational r)
{
return new Rational(r._numerator, r._denominator);
}
public static Rational operator -(Rational r)
{
return new Rational(-r._numerator, r._denominator);
}
public static Rational operator +(Rational r1, Rational r2)
{
BigInteger num1 = r1._numerator * r2._denominator;
BigInteger denom = r1._denominator * r2._denominator;
BigInteger num2 = r2._numerator * r1._denominator;
return new Rational(num1 + num2, denom);
}
public static Rational operator -(Rational r1, Rational r2)
{
BigInteger num1 = r1._numerator * r2._denominator;
BigInteger denom = r1._denominator * r2._denominator;
BigInteger num2 = r2._numerator * r1._denominator ;
return new Rational(num1 - num2 + m, denom);
}
public static Rational operator *(Rational r1, Rational r2)
{
BigInteger num = r1._numerator * r2._numerator ;
BigInteger denom = r1._denominator * r2._denominator ;
return new Rational(num, denom);
}
public static Rational operator /(Rational r1, Rational r2)
{
BigInteger num = r1._numerator * r2._denominator ;
BigInteger denom = r1._denominator * r2._numerator ;
return new Rational(num, denom);
}
public static Rational operator ^(Rational r1, int n)
{
BigInteger num = BigInteger.ModPow(r1._numerator, n, m) ;
BigInteger denom = BigInteger.ModPow(r1._denominator, n, m);
return new Rational(num, denom);
}
public int PQM()
{
_regularize();
return (int)(_numerator * BigInteger.ModPow(_denominator, m -2, m) % m);
}
}
package main
import (
"bufio"
"fmt"
"os"
)
func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] != ' ' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}
func readNum(scanner *bufio.Scanner) (a int) {
scanner.Scan()
readInt(scanner.Bytes(), 0, &a)
return
}
func readTwoNums(scanner *bufio.Scanner) (a int, b int) {
res := readNNums(scanner, 2)
a, b = res[0], res[1]
return
}
func readThreeNums(scanner *bufio.Scanner) (a int, b int, c int) {
res := readNNums(scanner, 3)
a, b, c = res[0], res[1], res[2]
return
}
func readNNums(scanner *bufio.Scanner, n int) []int {
res := make([]int, n)
x := 0
scanner.Scan()
for i := 0; i < n; i++ {
for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
x++
}
x = readInt(scanner.Bytes(), x, &res[i])
}
return res
}
func readUint64(bytes []byte, from int, val *uint64) int {
i := from
var tmp uint64
for i < len(bytes) && bytes[i] != ' ' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp
return i
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
tc := readNum(scanner)
for tc > 0 {
tc--
scanner.Scan()
bs := scanner.Bytes()
var N, K, M uint64
pos := readUint64(bs, 0, &N)
pos = readUint64(bs, pos+1, &K)
readUint64(bs, pos+1, &M)
res := solve(int64(N), int64(K), int64(M))
fmt.Println(res)
}
}
const MOD = 1e9 + 7
func pow(a, b int64) int64 {
var res int64 = 1
for b > 0 {
if b&1 == 1 {
res = (res * a) % MOD
}
a = (a * a) % MOD
b >>= 1
}
return res
}
func solve(N, K, M int64) int64 {
if M&1 == 1 {
a := pow(N, (M+1)>>1)
b := pow(N-1, (M+1)>>1)
c := pow(a, MOD-2)
return ((a - b + MOD) % MOD * c) % MOD
}
a := (pow(N, M/2) * (N + K)) % MOD
b := (pow(N-1, M/2) * (N + K - 1)) % MOD
c := pow(a, MOD-2)
return ((a - b + MOD) % MOD * c) % MOD
}
In our experience, we suggest you solve this Guess It Right CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.
If you are stuck anywhere between any coding problem, just visit Queslers to get the Guess It Right CodeChef Solution.
“I hope this Guess It Right CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.
Keep Learning!