結果
問題 | No.864 四方演算 |
ユーザー |
![]() |
提出日時 | 2019-08-16 21:35:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 1,000 ms |
コード長 | 2,538 bytes |
コンパイル時間 | 3,280 ms |
コンパイル使用メモリ | 196,988 KB |
最終ジャッジ日時 | 2025-01-07 12:12:17 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h>using namespace std;void *wmem;template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){static int skip[16]={0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};(*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );(*arr)=(T*)(*mem);(*mem)=((*arr)+x);}inline void rd(long long &x){int k, m=0;x=0;for(;;){k = getchar_unlocked();if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){k = getchar_unlocked();if(k<'0'||k>'9'){break;}x=x*10+k-'0';}if(m){x=-x;}}inline void wt_L(char a){putchar_unlocked(a);}inline void wt_L(long long x){char f[20];int m=0, s=0;if(x<0){m=1;x=-x;}while(x){f[s++]=x%10;x/=10;}if(!s){f[s++]=0;}if(m){putchar_unlocked('-');}while(s--){putchar_unlocked(f[s]+'0');}}template<class T> int Factor_L(T N, T fac[], int fs[]){T i;int sz=0;if(N%2==0){fac[sz] = 2;fs[sz] = 1;N /= 2;while(N%2==0){N /= 2;fs[sz]++;}sz++;}for(i=3;i*i<=N;i+=2){if(N%i==0){fac[sz] = i;fs[sz] = 1;N /= i;while(N%i==0){N /= i;fs[sz]++;}sz++;}}if(N > 1){fac[sz] = N;fs[sz] = 1;sz++;}return sz;}template<class T> int Divisor_L(T N, T res[], void *mem = wmem){T *fc;int *fs, fsz, i, j, k, s, sz=0;walloc1d(&fc, 100, &mem);walloc1d(&fs, 100, &mem);fsz =Factor_L(N, fc, fs);res[sz++] = 1;for(i=0;i<(fsz);i++){s = sz;k = s * fs[i];for(j=0;j<(k);j++){res[sz++] = res[j] * fc[i];}}sort(res, res+sz);return sz;}char memarr[96000000];long long N;long long K;long long ys;long long y[10000];long long cnt(long long a){if(a <= N+1){return a-1;}if(a <= 2*N){return 2*N+1-a;}return 0;}int main(){int i;long long res=0;wmem = memarr;rd(N);rd(K);ys =Divisor_L(K, y);for(i=0;i<(ys);i++){res += cnt(y[i]) * cnt(K/y[i]);}wt_L(res);wt_L('\n');return 0;}// cLay varsion 20190810-2// --- original code ---// ll N, K;// ll ys, y[10000];//// ll cnt(ll a){// if(a <= N+1) return a-1;// if(a <= 2N) return 2N+1-a;// return 0;// }//// {// int i;// ll res = 0;//// rd(N, K);// ys = Divisor(K, y);//// rep(i,ys) res += cnt(y[i]) * cnt(K/y[i]);// wt(res);// }