zoukankan      html  css  js  c++  java
  • Codeforces 1263C. Everyone is a Winner!(整除分块)

    传送门

    题意:

    输入一个数n,求出n/i(i取任意)向下取整有几种数,并输出

    思路:

    整除分块裸题

    for(int l=1,r;l<=n;l=r+1)
    {
        r=n/(n/l);
        a[++cnt]=n/l;
    }
     

    cnt代表分块的块的个数,每个块里的值为a[i]=n/l,l为块的左端点,r为块的右端点r=n/(n/l)

    代码:

    #include <iostream>
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    #include <vector>
    #include <math.h>
    #include <map>
    #include <queue>
    #include <set>
    using namespace std;
    typedef long long ll;
    const int N=2e6+50;
    const int mod=1e9+7;
    int a[N];
    map<int,int>mp;
    void solve(int t)
    {
        int n;scanf("%d",&n);
        int cnt=0;
        for(int l=1,r;l<=n;l=r+1)
        {
            r=n/(n/l);
            a[++cnt]=n/l;
        }
        printf("%d
    0 ",cnt+1);//别忘输出0,i大于n时,n/i都为0
        for(int i=cnt;i>=1;--i)
            printf("%d ",a[i] );
        printf("
    ");
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        int t;
        scanf("%d",&t);for(int i=1;i<=t;i++)solve(i);
        return 0;
    }
     
  • 相关阅读:
    JavaScript
    JavaScript
    目标
    pip安装问题:There was a problem confirming ssl certificate
    chromedriver,python国内镜像地址收集
    检查网络问题
    linux 三剑客
    常用linux命令
    KVM学习
    rsync笔记
  • 原文地址:https://www.cnblogs.com/zzl_Alexander/p/11965723.html
Copyright © 2011-2022 走看看