結果

問題 No.3152 neither multiple of A nor B
ユーザー ID 21712
提出日時 2025-06-09 01:38:54
言語 Go
(1.23.4)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 11,149 ms
コンパイル使用メモリ 233,360 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-06-09 01:39:10
合計ジャッジ時間 12,869 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import . "fmt"
import . "math/big"
import "math/rand"

func main() {
	var n, a, b int
	Scan(&n,&a,&b)
	Println(solve(n,a,b))
}

func solve(n, a, b int) int {
	gcd := new(Int).GCD(nil,nil,NewInt(int64(a)),NewInt(int64(b)))
	lcm := a*b/int(gcd.Int64())
	return n-n/a-n/b+n/lcm
}

func brutefoce(n, a, b int) int {
	ans := 0
	for i:=1; i<=n; i++ {
		if i%a!=0&&i%b!=0 {
			ans++
		}
	}
	return ans
}

func check() {
	for i := 0; i < 2000; i++ {
		n := rand.Intn(1e5)+1e4
		a := rand.Intn(n)+1
		b := rand.Intn(n)+1
		s1:=solve(n,a,b)
		s2:=solve(n,a,b)
		if s1!=s2 {
			println(Sprintf("n=%d,a=%d,b=%d,s1=%d,s2=%d",n,a,b,s1,s2))
			panic("bug")
		}
	}
	println("ok")
}

func init() {
	// check()
}
0