码迷,mamicode.com
首页 > Windows程序 > 详细

C. Everyone is a Winner!(整除分块)

时间:2019-12-01 13:28:09      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:div   std   onclick   typedef   map   article   void   property   def   

传送门

题意:

输入一个数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\n0 ",cnt+1);//别忘输出0,i大于n时,n/i都为0
    for(int i=cnt;i>=1;--i)
        printf("%d ",a[i] );
    printf("\n");
}
int main()
{
    //freopen("in.txt","r",stdin);
    int t;
    scanf("%d",&t);for(int i=1;i<=t;i++)solve(i);
    return 0;
}

 

 

C. Everyone is a Winner!(整除分块)

标签:div   std   onclick   typedef   map   article   void   property   def   

原文地址:https://www.cnblogs.com/zzl-dreamfly/p/11965723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!