Description
\quad On the well-known testing system MathForces, a draw of n rating units is arranged. The rating will be distributed according to the following algorithm: if k k k participants take part in this event, then the n n n rating is evenly distributed between them and rounded to the nearest lower integer, At the end of the drawing, an unused rating may remain — it is not given to any of the participants.
\quad For example, if n = 5 n=5 n=5 and k = 3 k=3 k=3, then each participant will recieve an 1 rating unit, and also 2 2 2 rating units will remain unused. If n = 5 n=5 n=5, and k = 6 k=6 k=6, then none of the participants will increase their rating.
\quad Vasya participates in this rating draw but does not have information on the total number of participants in this event. Therefore, he wants to know what different values of the rating increment are possible to get as a result of this draw and asks you for help.
\quad For example, if n = 5 n=5 n=5, then the answer is equal to the sequence 0 , 1 , 2 , 5 0,1,2,5 0,1,2,5. Each of the sequence values (and only them) can be obtained as ⌊n/k⌋ for some positive integer k k k (where ⌊ x ⌋ ⌊x⌋ ⌊x⌋ is the value of x rounded down): 0 = ⌊ 5 / 7 ⌋ 0=⌊5/7⌋ 0=⌊5/7⌋, 1 = ⌊ 5 / 5 ⌋ 1=⌊5/5⌋ 1=⌊5/5⌋, 2 = ⌊ 5 / 2 ⌋ , 5 = ⌊ 5 / 1 ⌋ . 2=⌊5/2⌋, 5=⌊5/1⌋. 2=⌊5/2⌋,5=⌊5/1⌋.
\quad Write a program that, for a given n, finds a sequence of all possible rating increments.
Input
\quad The first line contains integer number t ( 1 ≤ t ≤ 10 ) t (1≤t≤10) t(1≤t≤10) — the number of test cases in the input. Then t t t test cases follow.
\quad Each line contains an integer n ( 1 ≤ n ≤ 1 0 9 ) n (1≤n≤10^{9}) n(1≤n≤109) — the total number of the rating units being drawn.
Output
\quad Output the answers for each of t test cases. Each answer should be contained in two lines.
\quad In the first line print a single integer m m m — the number of different rating increment values that Vasya can get.
\quad In the following line print m m m integers in ascending order — the values of possible rating increments.
Example
input
4
5
11
1
3
output
4
0 1 2 5
6
0 1 2 3 5 11
2
0 1
3
0 1 3
\quad
题意就是给一个
n
n
n让你找
n
/
n/
n/任意数向下取整可以得到的值。
n
n
n有
1
0
9
10^{9}
109所以我们暴力枚举肯定是不超时的,但是数组会存不下,这里我们会发现一个规律就是枚举到
i
i
i是
n
/
i
n/i
n/i和
n
/
(
i
−
1
)
n/(i-1)
n/(i−1)的值一样时,后面所有的
0
−
n
/
i
0-n/i
0−n/i都会存在。
AC代码:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n,m) printf("%d %d", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sc(n) scanf("%c",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define mem(a,n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mod(x) ((x)%MOD)
#define gcd(a,b) __gcd(a,b)
#define lowbit(x) (x&-x)
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
int ret = 0, sgn = 1;
char ch = getchar();
while(ch < '0' || ch > '9')
{
if(ch == '-')
sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ret = ret*10 + ch - '0';
ch = getchar();
}
return ret*sgn;
}
inline void Out(int a) //Êä³öÍâ¹Ò
{
if(a>9)
Out(a/10);
putchar(a%10+'0');
}
int qpow(int m, int k, int mod)
{
int res = 1, t = m;
while (k)
{
if (k&1)
res = res * t % mod;
t = t * t % mod;
k >>= 1;
}
return res;
}
ll gcd(ll a,ll b)
{
return b==0?a : gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a*b/gcd(a,b);
}
int n;
int i,j,k;
int t;
int res,temp,cnt,num;
const int maxn = 1e7+10;
int ans[maxn];
bool vis[maxn];
int main()
{
sd(t);
while(t--)
{
sd(n);
mem(vis,0);
int cnt=0;
bool flag=0;
rep(i,1,n+1)
{
if(n/i==temp)
{
flag=1;
break;
}
else
{
ans[cnt++]=n/i;
temp=n/i;
}
}
if(flag)
{
cnt+=temp;
}
cout<<cnt<<endl;
rep(i,0,temp-1)
cout<<i<<" ";
for(int i=cnt-1-temp; i>=0; i--)
cout<<ans[i]<<" ";
cout<<endl;
}
return 0;
}