Submission #19236679


Source Code Expand

package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func gets() string {
	sc.Scan()
	return sc.Text()
}

func getInt() int {
	i, _ := strconv.Atoi(gets())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := getInt()

	ok, ng := big.NewInt(0), big.NewInt(1<<60)
	max := big.NewInt(int64(2 * (n + 1)))
	for {
		// mid := (ok + ng) / 2
		mid := new(big.Int).Div(new(big.Int).Add(ok, ng), big.NewInt(2))
		// sum := mid*(mid+1)
		sum := new(big.Int).Mul(mid, new(big.Int).Add(mid, big.NewInt(1)))
		// max >= sum ?
		if max.Cmp(sum) >= 0 {
			ok = mid
		} else {
			ng = mid
		}
		diff := new(big.Int).Sub(ng, ok)
		// ng-ok <= 1 ?
		if diff.Cmp(big.NewInt(1)) <= 0 {
			break
		}
	}

	// n + 1 - ok
	ans := big.NewInt(0).Sub(big.NewInt(int64(n+1)), ok)
	puts(ans)
}

Submission Info

Submission Time
Task B - log
User mutsuro_626
Language Go (1.14.1)
Score 400
Code Size 1122 Byte
Status AC
Exec Time 9 ms
Memory 1864 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 33
Set Name Test Cases
Sample sample.txt, sample_2.txt
All 1.txt, 1000000000000000000.txt, 11200.txt, 124503869.txt, 1312150450968416.txt, 15630162310904.txt, 19228110662.txt, 2.txt, 252509054433933446.txt, 27596462479.txt, 3.txt, 335408917861648771.txt, 39435.txt, 4.txt, 5.txt, 522842184971407774.txt, 55074593704796560.txt, 5952398887941493.txt, 5952398887941494.txt, 5952398887941495.txt, 635722518108209.txt, 645762258982631931.txt, 779547116602436425.txt, 812742.txt, 8150428669018.txt, 819875141880895727.txt, 822981260158260521.txt, 84324828731963981.txt, 919845426262703496.txt, 999999998765257139.txt, 999999999999999999.txt, sample.txt, sample_2.txt
Case Name Status Exec Time Memory
1.txt AC 9 ms 1852 KiB
1000000000000000000.txt AC 2 ms 1860 KiB
11200.txt AC 1 ms 1848 KiB
124503869.txt AC 1 ms 1844 KiB
1312150450968416.txt AC 1 ms 1848 KiB
15630162310904.txt AC 1 ms 1844 KiB
19228110662.txt AC 3 ms 1844 KiB
2.txt AC 2 ms 1848 KiB
252509054433933446.txt AC 1 ms 1848 KiB
27596462479.txt AC 1 ms 1844 KiB
3.txt AC 1 ms 1844 KiB
335408917861648771.txt AC 2 ms 1852 KiB
39435.txt AC 1 ms 1844 KiB
4.txt AC 2 ms 1844 KiB
5.txt AC 1 ms 1852 KiB
522842184971407774.txt AC 1 ms 1864 KiB
55074593704796560.txt AC 3 ms 1864 KiB
5952398887941493.txt AC 1 ms 1844 KiB
5952398887941494.txt AC 1 ms 1864 KiB
5952398887941495.txt AC 2 ms 1848 KiB
635722518108209.txt AC 2 ms 1848 KiB
645762258982631931.txt AC 1 ms 1844 KiB
779547116602436425.txt AC 3 ms 1848 KiB
812742.txt AC 5 ms 1844 KiB
8150428669018.txt AC 1 ms 1864 KiB
819875141880895727.txt AC 1 ms 1848 KiB
822981260158260521.txt AC 1 ms 1844 KiB
84324828731963981.txt AC 2 ms 1844 KiB
919845426262703496.txt AC 4 ms 1864 KiB
999999998765257139.txt AC 1 ms 1844 KiB
999999999999999999.txt AC 1 ms 1848 KiB
sample.txt AC 2 ms 1864 KiB
sample_2.txt AC 1 ms 1864 KiB