Problem:


B： えびちゃんと数列 - Ebi-chan and Integer Sequences -

問題

えびちゃんは数列が好きです。中でも等差数列が特に好きです。
今回は以下の条件を満たす数列を作ることにしました。

 長さ n の等差数列である

 数列の i 番目の要素を s_i と定める時、全ての s_i (1 \leq i \leq n) が 0 \leq s_i \leq m を満たす整数である

上の条件を満たすような数列はいくつあるでしょうか？
ただし答えは非常に大きくなることがあるので、 10^9 + 7 で割った余りを出力してください。

入力形式

入力は一行で与えられる。

n m

n は数列の長さを表す。

制約

 1 \leq n \leq 10^{15}

 0 \leq m \leq 10^{15}

出力形式

条件を満たす等差数列の数を 10^9 + 7 で割った余りを一行に出力せよ。

入力例1

3 9

出力例1

50

入力例2

10000000000 10000000000

出力例2

999999942

入力は32bit整数には収まりきらないことに注意してください。


Sample input:
3 9


Sample output:
50

Submission status: Wrong Answer

Solution code:
n, m = map(int, input().split())

MOD = 10**9 + 7
if n == 1:
    print(m+1)
else:
    k = m//(n-1)
    res = m+1 + 2*(m*k - k*(k+1)*(n-1)//2+k)
    print(res % MOD)

Submission status: Wrong Answer

Solution code:
x = input().split()

n = int(x[0])
m = int(x[1])

if n == 1:
	print(m+1)
else:
	b = m // (n-1)
	sum = (b-1) * b * (n-1)
	sum += 2 * b * (m - (n-1) * b + 1)
	sum += (m+1)
	print(sum % 1000000007)

Submission status: Wrong Answer

Solution code:
s = input()
n, m = s.split()
n = int(n)
m = int(m)

if n==1:
    print(m+1)
else:

    maxd = m // (n - 1)


    A = m - maxd * (n-1) + 1
    B = m - (n-1) + 1
    ans = (A+B)*maxd + (m+1)
    ans %= 1000000007
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n, m = s.split()
n = int(n)
m = int(m)

if n==1:
    print(m+1)
else:

    d = m // (n - 1)


    A = m - d * (n-1) + 1
    B = m - (n-1) + 1
    # ans = (A+B)*d + (m+1)
    ans = 2*(d*m+d)-(n-1)*(d+1)*d+m+1
    ans %= 1000000007
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
n, m = s.split()
n = int(n)
m = int(m)

if n==1:
    print(m+1)
else:

    d = m // (n - 1)


    A = m - d * (n-1) + 1
    B = m - (n-1) + 1
    ans = (A+B)*d + (m+1)
    # ans = 2*(d*m+d)-(n-1)*(d+1)*d+m+1
    print(ans)

Submission status: Wrong Answer

Solution code:
asd = raw_input()
asdd = asd.split()
n = int(asdd[0])
m = int(asdd[1])
if n == 1:
    print m+1%1000000007
    exit(0)

x=(m+1)/(n-1)
print (2*((m+1)*x-x*(n-1)*(x+1)/2)+m+1)%1000000007

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
if(n == 1):
    ans = (m+1)%1000000007
    print(int(m+1))
else:
    d = int(m/(n-1))
    ans = (m+1)*d - d*(d+1)/2*(n-1)
    ans *= 2
    ans += (m+1)
    ans %= 1000000007
    print(int(ans))

Submission status: Accepted

Solution code:
MOD = 10**9+7

def sum(a,d,n):
    return n*(2*a+(n-1)*d)//2

def main():
    n,m = map(int,input().split())

    s = 0
    if n == 1:
        s = m+1
    else:
        s = sum(m+1,-n+1,1+m//(n-1))
        s *= 2
        s -= (m+1)

    print(s%MOD)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

MOD = 10**9 + 7
if n == 1:
    print((m+1) % MOD)
else:
    k = m//(n-1)
    res = m+1 + 2*(m*k - k*(k+1)*(n-1)//2+k)
    print(res % MOD)

Submission status: Accepted

Solution code:
r = 1000000007

n, m = input().split()
n = int(n)
m = int(m)

if n==1:
	output = (m+1)%r
	print(output)
else:
	l = (m+1) // (n-1) + 1
	a = (m+1) - ((m+1) // (n-1)) * (n-1)
	e = m+1

	output = ((a+e)*l) // 2

	output = 2*output - (m+1)
	output = output % r

	print(output)

Submission status: Accepted

Solution code:
s = input()
n, m = s.split()
n = int(n)
m = int(m)

if n==1:
    print((m+1)%1000000007)
else:

    d = m // (n - 1)


    A = m - d * (n-1) + 1
    B = m - (n-1) + 1
    ans = (A+B)*d + (m+1)
    # ans = 2*(d*m+d)-(n-1)*(d+1)*d+m+1
    ans %= 1000000007
    print(ans)

Submission status: Accepted

Solution code:
asd = raw_input()
asdd = asd.split()
n = int(asdd[0])
m = int(asdd[1])
if n == 1:
    print (m+1)%1000000007
    exit(0)

x=(m+1)/(n-1)
print (2*((m+1)*x-x*(n-1)*(x+1)/2)+m+1)%1000000007

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if(n == 1):
    ans = (m+1)%1000000007
    print(ans)
else:
    d = int(m//(n-1))
    ans = (m+1)*d - d*(d+1)//2*(n-1)
    ans *= 2
    ans += (m+1)
    ans %= 1000000007
    print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
mod1,mod2=10**9+7,998244353
mod=mod1
ans=(m+1)%mod
if n!=1:
    a=m//(n-1)
    ans=((m+1)*(a+1)+(m+1)*a-(n-1)*a*(a+1))%mod
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
n, m = s.split()
n = int(n)
m = int(m)

maxd = m // (n - 1)

A = m - maxd * (n-1) + 1
B = m - (n-1) + 1
ans = (A+B)*maxd + (m+1)
ans %= 1000000007
print(ans)

Submission status: Runtime Error

Solution code:
asd = raw_input()
asdd = asd.split()
n = int(asdd[0])
m = int(asdd[1])
x=(m+1)/(n-1)
print (2*((m+1)*x-x*(n-1)*(x+1)/2)+m+1)%1000000007

Submission status: Runtime Error

Solution code:
asd = raw_input()
asdd = asd.split()
n = int(asdd[0])
if n == 1:
    print m+1%1000000007
    exit(0)
m = int(asdd[1])
x=(m+1)/(n-1)
print (2*((m+1)*x-x*(n-1)*(x+1)/2)+m+1)%1000000007