結果

問題 No.864 四方演算
ユーザー yu-ta38
提出日時 2022-06-05 17:25:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 19 ms / 1,000 ms
コード長 7,367 bytes
コンパイル時間 1,583 ms
コンパイル使用メモリ 117,436 KB
最終ジャッジ日時 2025-01-29 18:33:36
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <iomanip>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
typedef long long int ll;
typedef pair<int, int> Pint;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
struct dsu {
vector<int> d;
dsu(int n = 0): d(n,-1) {}
int findRoot(int x) {
if(d[x] < 0) return x;
return d[x] = findRoot(d[x]);
}
bool unite(int x,int y) {
x = findRoot(x); y = findRoot(y);
if(x == y) return false;
if(d[x] > d[y]) swap(x,y);
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x,int y) { return findRoot(x) == findRoot(y);}
int size(int x) {return -d[findRoot(x)];}
};
template <typename T>
struct RMQ {
const T INF = numeric_limits<T>::max();
int n;
vector<T> dat;
RMQ(int n_) : n(), dat(n_ * 4, INF) {
int x = 1;
while(n_ > x) {
x *= 2;
}
n = x;
}
void update(int i, T x) {
i += n - 1;
dat[i] = x;
while(i > 0) {
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
T query(int a, int b) { return query_sub(a,b,0,0,n); }
T query_sub(int a, int b, int k, int l, int r) {
if(r <= a || b <= l) {
return INF;
}else if(a <= l && r <= b) {
return dat[k];
}else {
T vl = query_sub(a,b,k * 2 + 1, l, (l + r) / 2);
T vr = query_sub(a,b,k * 2 + 2, (l + r) / 2, r);
return min(vl, vr);
}
}
};
struct Edge {
int to;
ll w;
Edge(int to, ll w) : to(to), w(w) {}
};
using WeightedGraph = vector<vector<Edge>>;
//
vector<ll> dijkstra(WeightedGraph Graph,int N, int s);
double getDistance(double x1, double y1, double x2, double y2);
double getAngle(double xa, double ya, double xb, double yb, double xc, double yc);
bool primeCheck(ll N);
template<class T> bool chmax(T& a, T b);
template<class T> bool chmin(T& a, T b);
template<class T> T base_n_to_ll(string S, T n);
template<class T> string ll_to_base_n(T num, T n);
template<class T> vector<T> divisorEnumeration(T K);
template<class T> vector<T> primeFactorization(T N);
template<class T> vector<T> cumulativeSum(vector<T> a);
ll hspow(ll a, ll n);
ll modpow(ll a, ll n, ll mod);
ll modinv(ll a, ll b, ll mod);
ll simpleCombination(ll n, ll r);
ll modCombination(ll n, ll r, ll mod);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
#define MOD (int)998244353
// solve()
// Global3e8
const int MAX_N = 200005;
void solve() {
ll N,K; cin>>N>>K;
vector<ll> divisor = divisorEnumeration(K);
ll ans = 0;
for(auto t : divisor) {
ll x,y;
ll mid = (2 * N + 2) / 2;
if(t<=1||2*N<t) x = 0;
else if(2<=t&&t<=mid) x = t - 1;
else x = mid * 2 - t - 1;
ll t_ = K/t;
if(t_<=1||2*N<t_) y = 0;
else if(2<=t_&&t_<=mid) y = t_ - 1;
else y = mid * 2 - t_ - 1;
// cout<<x<<' '<<y<<endl;
ans += (x * y);
}
cout<<ans<<endl;
}
int main() {
solve();
return 0;
}
// *****************
// *****************
// * function *
// *****************
// *****************
bool primeCheck(ll N) {
for (ll i = 2; i * i <= N; i++) {
if (N % i == 0) return false;
}
return true;
}
double getDistance(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double getAngle(double xa, double ya, double xb, double yb, double xc, double yc) {
double VectorAB = sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
double VectorAC = sqrt((xc - xa) * (xc - xa) + (yc - ya) * (yc - ya));
double Naiseki = (xb - xa) * (xc - xa) + (yb - ya) * (yc - ya);
double cosTheta = Naiseki / (VectorAB * VectorAC);
return acos(cosTheta) * 180.0 / M_PI;
}
template<class T> vector<T> cumulativeSum(vector<T> a) {
T sum = 0, n = a.size();
vector<T> s(n+1);
s[0] = 0;
for(int i = 1;i <= n;++i) {
s[i] = a[i] + s[i-1];
}
return s;
}
long long simpleCombination(long long n, long long r) {
long long sum = 1;
if(r > n - r) r = n - r;
for(int i = 1;i <= r;++i) {
sum *= (n - i + 1);
sum /= i;
}
return sum;
}
long long modCombination(long long n, long long r, long long mod) {
long long sum = 0, a = 1, b = 1, condition;
if(n/2 < r) r = n - r;
condition = n - r;
for(int i = 1;i <= n;++i) {
if(i <= r) {
b = (b * i) % mod;
}
if(i > condition) {
a = (a * i) % mod;
}
}
sum = modinv(a, b, mod);
return sum;
}
ll hspow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
long long modinv(long long a, long long b, long long mod) {
return a * modpow(b, mod - 2, mod) % mod;
}
ll gcd(ll a, ll b) {if(b == 0) return a;else {return gcd(b, a%b);}}
ll lcm(ll a, ll b) {return a * gcd(a,b) / b;}
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> T base_n_to_ll(string S, T n) {
T res = 0;
rep(i,S.size()) {
res = res*n + (S[i]-'0');
}
return res;
}
template<class T> string ll_to_base_n(T num, T n) {
if(num == 0) return "0";
string res = "";
while(num>0) {
res = char((num%n) + '0') + res;
num /= n;
}
return res;
}
template<class T> vector<T> divisorEnumeration(T K) {
vector<T> divisor;
for(T i = 1; i * i <= K; i++) {
if(K % i != (T)0) continue;
divisor.push_back(i);
if(i != (K / i)) divisor.push_back(K / i);
}
sort(divisor.begin(),divisor.end());
return divisor;
}
template<class T> vector<T> primeFactorization(T N) {
vector<T> prime;
for(T i = 2; i * i <= N; i++) {
while(N % i == 0) {
N /= i;
prime.push_back(i);
}
}
if(N != (T)1) prime.push_back(N);
return prime;
}
vector<ll> dijkstra(WeightedGraph Graph,int N, int s) {
vector<ll> dist(N,INF);
dist[s] = 0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que;
que.push(make_pair(dist[s],s));
while(!que.empty()) {
int v = que.top().second;
ll d = que.top().first;
que.pop();
if(d > dist[v]) continue;
for(auto e : Graph[v]) {
if(chmin(dist[e.to], dist[v] + e.w)) {
que.push(make_pair(dist[e.to],e.to));
}
}
}
return dist;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0