0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AGC 001 B Mysterious Light

Last updated at Posted at 2020-07-26

問題

見た感じ

Nがめちゃくちゃでかくなるので、1手ずつ数えていくのでは間に合わない。
だから、手元で図を描いたりして見ると、おんなじ長さの辺を一気に書いていって、書けなくなったら、次の長さに移っていくという書かれ方をしていて、かつ平行四辺形がたくさん出てくるのに気づいた。
ここから、$n\times m(n>m)$の平行四辺形に注目してその中でできるだけ大きな正三角形をできるだけ多く書くとき、最初の点に戻るとしたらそれまでに

2*(\lfloor n/m\rfloor -1)*m

書き加えているし最初の点に戻らないときは

2*\lfloor n/m\rfloor *m

書きくわえて、$m\times n%m$の平行四辺形に移るを繰り返す。
これを実装すればおk

解法

上の再帰的な操作を繰り返す。

ソースコード

ll n,x;

void Main(){
    int y=INF10,z=1;
    //入力
    cin>>n>>x;
    //処理
    ll res=0,a,b,c;

    a=max(n-x,x);
    b=min(x,n-x);
    res=n;
    while(b!=0){
        if(a%b==0){
            res+=((a/b)-1)*2*b+b;
        }else{
            res+=(a/b)*2*b;
        }
        c=b;
        b=a%b;
        a=c;
    }
    
    //出力
    cout << res <<endl;
}

int main(){
    cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    Main();
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?