結果

問題 No.864 四方演算
ユーザー snow39
提出日時 2019-08-16 21:55:38
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 748 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 95,908 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 10:46:08
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N,K;

int main(){
  cin>>N;
  cin>>K;
  vector<ll> v;
  for(ll i=1;i*i<=K;i++){
    if(K%i==0){
      v.push_back(i);
    }
  }

  ll eq=0,ans=0;
  for(int i=0;i<v.size();i++){
    ll p=v[i],q=K/v[i];  
      ll x=0,y=0;
      if(p-1<=N) x=p-1;
      else{
        x=p-1-2*((p-1)-N);
        if(x<0) x=0;
      }

      if(q-1<=N) y=q-1;
      else{
        y=q-1-2*((q-1)-N);
        if(y<0) y=0;
      }

      if(p==q) eq+=x*y;
      else ans+=x*y;
  }

  cout<<ans*2+eq<<endl;

  return 0;
}
0