0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

mylist

Last updated at Posted at 2025-07-30
**素因数列挙**
//O(sqrt(N))
vector<int> pfact(int x){
  vector<int> res;
  for(int i=2;i*i<=x;i++){
    while(x%i==0){
      x/=i;
      res.push_back(i);
    }
  }
  if(x!=1){res.push_back(x);}
  return res;
}
**最大公約数・最大公約数列挙/最小公倍数・最小公倍数列挙**
long int gcd(long int a, long int b) {
    return b ? gcd(b, a%b) : a;
}
int ngcd(vector<int> a){
    int res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int nlcm(vector<int> numbers) {
    int res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
**nCr**
int64_t con(int x,int y){
  int64_t r=1;
  if(x<y*2)
    y=x-y;
  for(int i=1;i<=y;i++)  {
    r*=(x-y+i);
    r/=i;
  }
  return r;
}
**約数列挙**
vector<long long> enum_div(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i != 0) continue;
        res.push_back(i);
        if (N / i != i) res.push_back(N / i);
    }
    sort(res.begin(), res.end());
    return res;
}
**配列loopの開始位置をずらす**
    std::vector<int> vec{0, 1, 2, 3, 4};
    int shifts = 0;
    int n = -1; //ずらす数
    shifts = (shifts + vec.size() + n) % vec.size();
    for (int i = 0; i < vec.size(); ++i) {
        std::cout << vec[(i + shifts) % vec.size()] << std::endl;
    }
**リングキューのdistance**
dis = (end - start + size) % size;

image.png

**charをintに変換**
int v = static_cast<int>(c - '0');
**配列から2を選ぶ組み合わせ数**

image.png

N * (n - 1) / 2;
**区間の組み合わせ数**

image.png

N * (n + 1) / 2;
**両端からのfor文探査**

image.png

for (int l = 0, r = N - 1; l < r; ++l, --r) {
}
**切り捨て除算**

一般に、A を B で切り捨て除算したい場合は、

A,B ともに正の場合 A / B
A,B が負を取り得る場合 A / B - (A % B < 0)
https://atcoder.jp/contests/abc239/editorial/3390

**K 進法表記の S を、10 進法表記で表す関数**
ll f(string s,ll k){ // 
    ll ans=0;
    for(char x:s){
        ans *= k;
        ans += x - '0';
    }
    return ans;
}
**回文になっているか**
stringにして反転
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?