結果

問題 No.982 Add
コンテスト
ユーザー cureskol
提出日時 2020-02-11 16:13:25
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,371 ms / 2,000 ms
コード長 439 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,241 ms
コンパイル使用メモリ 186,572 KB
実行使用メモリ 134,752 KB
最終ジャッジ日時 2026-04-17 08:24:12
合計ジャッジ時間 25,675 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:17:9: warning: ignoring return value of '_FIter std::unique(_FIter, _FIter) [with _FIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]', declared with attribute 'nodiscard' [-Wunused-result]
   17 |   unique(v.begin(),v.end());
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/algorithm:63,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:53,
                 from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algo.h:875:5: note: declared here
  875 |     unique(_ForwardIterator __first, _ForwardIterator __last)
      |     ^~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int a,b;cin>>a>>b;
  if(__gcd(a,b)>1)fin(-1);
  vector<int> v;
  if(a>b)swap(a,b);
  for(int i=0;i<5000;i++)for(int j=0;j<5000;j++)v.push_back(a*i+b*j);
  sort(v.begin(),v.end());
  unique(v.begin(),v.end());
  int ans=0;
  for(int i=0;i<100000;i++)
    if(v[i]<=a*b)
      ans+=v[i+1]-v[i]-1;
  fin(ans);
}
0