結果
問題 | No.141 魔法少女コバ |
ユーザー |
![]() |
提出日時 | 2016-06-22 20:52:41 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 402 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 58,640 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 19:23:43 |
合計ジャッジ時間 | 4,273 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
ソースコード
#include<iostream> #include<algorithm> using namespace std; int main(){ long long M,N; long long c=0; cin>>M>>N; for(int i=2;i<1000000;i++){ while(M%i==0&&N%i==0){ M/=i; N/=i; } } while(M!=1||N!=1){ if(M<0||N<=0){ cout<<"-1"<<endl; return 0; } if(M<N){ c++; swap(M,N); } if(N!=1){ c+=M/N; M%=N; } else{ c+=M-1; M=1; } } cout<<c<<endl; }