Pierre is recently obsessed with an online game. To encourage users to log in, this game will give users a continuous login reward. The mechanism of continuous login reward is as follows: If you have not logged in on a certain day, the reward of that day is 0, otherwise the reward is the previous day's plus 1.

On the other hand, Pierre is very fond of the number N. He wants to get exactly N points reward with the least possible interruption of continuous login.

Input

There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:

There is one integer N (1 <= N <= 123456789).

Output

For each test case, output the days of continuous login, separated by a space.

This problem is special judged so any correct answer will be accepted.

Sample Input

4 20 19 6 9 

Sample Output

4 4 3 4 2 3 2 3 

Hint

20 = (1 + 2 + 3 + 4) + (1 + 2 + 3 + 4)

19 = (1 + 2 + 3) + (1 + 2 + 3 + 4) + (1 + 2)

6 = (1 + 2 + 3)

9 = (1 + 2) + (1 + 2 + 3)

题意:给出n求出最少要用多少等差数列的连续和组成。

sl:本以为是dp没想到n这么大,天啊,跳河,之后就没做,只敲了下dp代码看了看有没有什么规律。

打了表没看出来。后来才知道原来最终结果不超过3,再看看我的表确实如此。有表都没看出规律。

之后就是暴力枚举了。 时间复杂度是1e6刚好。

外付打表代码。

 1 //water
 2 /*
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<cmath>
 8 using namespace std;
 9 typedef long long LL;
 const int inf = 0x3f3f3f3f;
 const int MAX = 1e6+10;
 int dp[MAX];
 int main()
 {
     int n;
     while(scanf("%d",&n)==1)
     {
         for(int i=0;i<MAX;i++) dp[i]=inf;
         dp[1]=1; dp[0]=0;
         for(int i=2;i<100;i++)
         {
             for(int j=1;j<100;j++)
             {
                 int t=(i-j+1)*(1+i-j+1)/2;
                 if(t<=i)
                 dp[i]=min(dp[i],dp[i-t]+1);
             }
         }
         printf("%d\n",dp[n]);
     }
     return 0;
 }
 全然不超过3个
 */
 #include <cstring>
 #include <algorithm>
 #include <cstdio>
 #include <map>
 using namespace std;
 const int MAX = 1e6+;
 map<int,int> val;
 map<int,int> cnt;
 
 void init()
 {
     int start=; int cur=; int a=;
     while(start<=)
     {
         val[cur]=start;
         cnt[start]=cur;
         a++;
         start+=a;
         cur++;
     }
 }
 
 int main()
 {
     int cas,n;
     scanf("%d",&cas);
     while(cas--)
     {
         val.clear(); cnt.clear();
         init();
         scanf("%d",&n);
 
         if(cnt[n])
         printf("%d\n",cnt[n]);
         else
         {
             int end=; int flag=;
             while(val[end]<n) end++;
             for(int i=;i<=end;i++)
             {
                 if(val[n-val[i]])
                 {
                     flag=;
                     printf("%d %d\n",cnt[val[i]],cnt[n-val[i]]);
                 }
             }
             for(int i=;i<=end&&flag;i++)
             {
                 for(int j=end;j>=&&flag;j--)
                 {
                     int t=n-val[j]-val[i];
                     if(t>)
                     {
                         if(val[t])
                         {
                             printf("%d %d %d\n",cnt[val[i]],cnt[val[j]],cnt[t]);
                         }
                     }
                 }
             }
         }
     }
 
     return ;
 }

最新文章

  1. selenium support
  2. MariaDB远程连接配置
  3. object-c 基本数据类型
  4. linux两种增加交换分区(swap)的方法
  5. PL/SQL常见设置--Kevin的专栏
  6. BZOJ 2298 problem a(区间DP)
  7. (摘录)MSMQ的简单介绍
  8. iOS 之 alcatraz (插件管理器)
  9. Python 之 基础知识(一)
  10. c# 中的封装、继承、多态详解
  11. (error) LOADING Redis is loading the dataset in memory
  12. Spring Boot项目打包部署到外部Tomcat
  13. jquery插件artTxtCount输入字数限制,并提示剩余字数
  14. 安装svn过程
  15. FFmpeg(8)-打开音视频解码器,配置解码器上下文(avcodec_find_decoder()、avcodec_alloc_context3())
  16. 如果要写php扩展啥的, 要看什么?
  17. MultiplyVector方法
  18. Centos下telnet的安装和配置
  19. 我的&quot;gethup&quot;(GitHub)注册之旅
  20. WebService发布协议--SOAP和REST的区别

热门文章

  1. bzoj 1778: [Usaco2010 Hol]Dotp 驱逐猪猡【dp+高斯消元】
  2. P4576 [CQOI2013]棋盘游戏
  3. ASP.NET 知识点总结(六)
  4. magento Grid 显示下拉菜单属性
  5. 19 C#循环语句的跳过和中断 continue和break
  6. vue 父子组件双向绑定
  7. Python中深拷贝与浅拷贝的区别
  8. oracle in表达式参数支持最大上限1000个
  9. &quot;HybridDB &#183; 性能优化 &#183; Count Distinct的几种实现方式” 读后感
  10. 左耳听风 ARTS Week 001