提出 #27234105


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */ 
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

vector<int> mark(N, false);
vector<long long> primes;

vector<vector<int>> segmentedSieve(long long L, long long R) {
    long long lim = sqrt(R);
    vector<vector<int>> isPrime(R - L + 1);
    for (long long i : primes){
        for (long long j = max(i * i, (L + i - 1) / i * i); j <= R; j += i){
            isPrime[j - L].push_back(i);
        }
    }
    if (L == 1)
        isPrime[0] = {1};
    return isPrime;
}


signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    for(int i = 2; i < N; i++)
        mark[i] = i;
    for (long long i = 2; i < N; ++i) {
        if (mark[i] == i) {
            primes.emplace_back(i);
            for (long long j = i * i; j < N; j += i)
                mark[j] = i;
        }
    }
    // cin>>TESTS;
    while(TESTS--)
    {   
        int n, k;
        cin >> n >> k;
        if(k == 0 or k == n) {
            cout << 1 << endl;
            continue;
        }
        unordered_map<int,int> l;
        for(int i = 1; i <= k; i++) {
            int t = i;
            while(t > 1) {
                // trace(t, mark[t]);
                l[mark[t]]--;
                t /= mark[t];
            }
        }
        // trace(l);
        auto p = segmentedSieve(n-k+1, n);
        for(int i = 0; i < k; i++) {
            vector<int> pri = p[i];
            int temp = n-k+1+i;
            for(auto i : pri) {
                while(temp % i == 0) {
                    temp /= i;
                    l[i]++;
                }
            }
            if(temp > 1) l[temp]++;
        }
        // trace(l);
        int ans = 1;
        for(auto j : l) {
            ans = (ans * (j.sc + 1)) % U;
        }
        cout << ans << endl;
    }
}

提出情報

提出日時
問題 G - Divisors of Binomial Coefficient
ユーザ adarshagr8
言語 C++ (GCC 9.2.1)
得点 600
コード長 3706 Byte
結果 AC
実行時間 1263 ms
メモリ 113248 KiB

コンパイルエラー

./Main.cpp: In function ‘std::string to_string(std::vector<std::vector<_Tp> >)’:
./Main.cpp:33:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   33 |   for (auto x: v) r += "\n" + to_string(x); return r;}
      |   ^~~
./Main.cpp:33:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   33 |   for (auto x: v) r += "\n" + to_string(x); return r;}
      |                                             ^~~~~~
./Main.cpp: In function ‘std::vector<std::vector<long long int> > segmentedSieve(long long int, long long int)’:
./Main.cpp:48:15: warning: unused variable ‘lim’ [-Wunused-variable]
   48 |     long long lim = sqrt(R);
      |               ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 40
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 22 ms 11928 KiB
random_02.txt AC 18 ms 11880 KiB
random_03.txt AC 27 ms 12000 KiB
random_04.txt AC 104 ms 24524 KiB
random_05.txt AC 21 ms 12004 KiB
random_06.txt AC 546 ms 63116 KiB
random_07.txt AC 26 ms 11900 KiB
random_08.txt AC 410 ms 52796 KiB
random_09.txt AC 24 ms 11948 KiB
random_10.txt AC 309 ms 46440 KiB
random_11.txt AC 1242 ms 113156 KiB
random_12.txt AC 69 ms 18476 KiB
random_13.txt AC 26 ms 12000 KiB
random_14.txt AC 1028 ms 99508 KiB
random_15.txt AC 29 ms 11896 KiB
random_16.txt AC 81 ms 20588 KiB
random_17.txt AC 563 ms 66696 KiB
random_18.txt AC 215 ms 34312 KiB
random_19.txt AC 962 ms 97352 KiB
random_20.txt AC 83 ms 20320 KiB
random_21.txt AC 1254 ms 112388 KiB
random_22.txt AC 251 ms 39328 KiB
random_23.txt AC 1073 ms 102820 KiB
random_24.txt AC 30 ms 11876 KiB
random_25.txt AC 219 ms 36004 KiB
random_26.txt AC 236 ms 37724 KiB
random_27.txt AC 476 ms 62268 KiB
random_28.txt AC 24 ms 12004 KiB
random_29.txt AC 20 ms 11820 KiB
random_30.txt AC 25 ms 11924 KiB
random_31.txt AC 1263 ms 113132 KiB
random_32.txt AC 456 ms 55764 KiB
random_33.txt AC 27 ms 11820 KiB
random_34.txt AC 1260 ms 113248 KiB
random_35.txt AC 320 ms 48172 KiB
random_36.txt AC 27 ms 12060 KiB
random_37.txt AC 24 ms 12004 KiB
sample_01.txt AC 20 ms 11816 KiB
sample_02.txt AC 20 ms 12008 KiB
sample_03.txt AC 1263 ms 113000 KiB