C. Everyone is a Winner!(整除分块)
Posted zzl-dreamfly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C. 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; }
以上是关于C. Everyone is a Winner!(整除分块)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #603 (Div. 2) C.Everyone is A Winner!
Gym 100712A - Who Is The Winner
Gym 100952 A. Who is the winner?
CodeForces-2015 HIAST Collegiate Programming Contest-Gym-100952A-Who is the winner?
Gym 100952A&&2015 HIAST Collegiate Programming Contest A. Who is the winner?字符串,暴力