给定你一个n,让你求出所有的n/i(下取整)
这道题想了很久,打表发现了规律,每个值相同的块,最后一个因子都是n/(n/i),但找到规律以后不知道该如何实现,看了题解以后才发现这是一道整数分块的问题。 核心代码:
int cnt=1;
for(int l=1,r;l<=n;l=r+1){
r=n/(n/l);
a[cnt++]=n/l;
}
#include<bits/stdc++.h>
#define x first
#define y second
#pragma GCC optimize(2)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=100010;
const int M=1e6;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
int n,m;
int a[N];
int main()
{
IOS;
int T;cin>>T;
while(T--){
int n;cin>>n;
int cnt=1;
for(int l=1,r;l<=n;l=r+1){
r=n/(n/l);
a[cnt++]=n/l;
}
sort(a,a+cnt);
cout<<cnt<<endl;
for(int i=0;i<cnt;i++) cout<<a[i]<<' ';
cout<<endl;
}
return 0;
}