1018: Give me the answer

时间限制: 1 Sec  内存限制: 32 MB
提交: 55  解决: 15
[提交][状态][讨论版][命题人:外部导入]

题目描述

Farmer John commanded his cows to search for different sets of numbers that sum to a given number.
The cows use only numbers that are an integer power of 2. Here are the possible sets of numbers that
sum to 7:
1) 1+1+1+1+1+1+1
2) 1+1+1+1+1+2
3) 1+1+1+2+2
4) 1+1+1+4
5) 1+2+2+2
6) 1+2+4
Help FJ count all possible representations for a given integer N (1 <= N <= 1 ,000,000)

输入

The first line of the input contains the number of test cases in the file. And t he first line of each case
contains one integer numbers n

输出

For each test case, output a line with the ans % 1000000000.

样例输入

1
7

样例输出

6
#include<stdio.h>
#define MAX 1000010
int a[MAX];
int main()
{
int n, m, i;
a[1] = 1;
a[2] = 2;
for(i = 3; i <= MAX; ++i)
{
if(i & 1)
a[i] = a[i - 1] % 1000000000;
else
a[i] = (a[i - 1] + a[i / 2]) % 1000000000;
}
scanf("%d", &n);
while(n--)
{
scanf("%d", &m);
printf("%d\n", a[m]);
}
return 0;
}

  

 

1018: Give me the answer的更多相关文章

  1. CodeForces - 662A:Gambling Nim (求有多少个子集其异或为S)(占位)

    As you know, the game of "Nim" is played with n piles of stones, where the i-th pile initi ...

  2. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  3. A - Divide it! CodeForces - 1176A

    题目: You are given an integer nn. You can perform any of the following operations with this number an ...

  4. CodeForces - 1176A Divide it! (模拟+分类处理)

    You are given an integer nn. You can perform any of the following operations with this number an arb ...

  5. Codeforces1176A(A题)Divide it!

    Divide it! You are given an integer nn. You can perform any of the following operations with this nu ...

  6. GSS4 - Can you answer these queries IV(线段树懒操作)

    GSS4 - Can you answer these queries IV(线段树懒操作) 标签: 线段树 题目链接 Description recursion有一个正整数序列a[n].现在recu ...

  7. 【LEETCODE】53、数组分类,简单级别,题目:989、674、1018、724、840、747

    真的感觉有点难... 这还是简单级别... 我也是醉了 package y2019.Algorithm.array; import java.math.BigDecimal; import java. ...

  8. SPOJ GSS3 Can you answer these queries III[线段树]

    SPOJ - GSS3 Can you answer these queries III Description You are given a sequence A of N (N <= 50 ...

  9. PAT A 1018. Public Bike Management (30)【最短路径】

    https://www.patest.cn/contests/pat-a-practise/1018 先用Dijkstra算出最短路,然后二分答案来验证,顺便求出剩余最小,然后再从终点dfs回去求出路 ...

随机推荐

  1. 技巧:Python中print打印信息的同时打印文件、行号

    import sys def Log(msg): print('Print Message: '+msg+' ,File: "'+__file__+'", Line '+str(s ...

  2. Should I buy Auro OtoSys IM600 or Obdstar X300 DP?

    Auro OtoSys IM600 and Obdstar X300 DP – What’s the difference & Which better? This is for those ...

  3. 第一章javascript简介

    javascript 当诞生于1995 最开始是目的是处理在服务器端进行的表单验证:让其在服务器端验证改为在服务端验证,大大提高速度(当时网络慢) 如今javascript是一门功能全面的语言,包含闭 ...

  4. 结合element-ui表格自动生成sku规格列表

    最近在写一个根据输入的规格,属性值动态生成sku表格,实现的效果大致如图,这是在vue项目里,结合element-UI表格写的,写好了就整理了一下,把代码贴上来,方便以后使用,不过代码里还是有一些重复 ...

  5. java——二分搜索树 BST(递归、非递归)

    ~ package Date_pacage; import java.util.Stack; import java.util.ArrayList; import java.util.LinkedLi ...

  6. win10重装完登录不了微软账号

    in10重装完登录不了微软账号解决方法如下: 点击win键+R,然后输入services.msc回车,进入本地服务管理,查看以下服务是否正常启用了: Microsoft Account Sign-in ...

  7. DataFrame的数据类型转换

    dfxxx['username']=pd.to_numeric(dfxxx['username'],errors='coerce')#将不能转换数据类型的值强制转换成NaN dfxxx['userna ...

  8. Linux下wget下载软件小技巧以及安装jdk、tomcat与ftp服务器

    一.ftp的安装 装个ftp搞了一下午,感觉以前没那么麻烦的呀,结果到晚上才发现是实验室网的问题,换连手机的热点马上可以了,真是尴尬,把基本安装步骤记录一下: 1.检查安装vsftpd软件 使用如下命 ...

  9. Kure讲HTML_列表标签及表单标签

    首先我上个图来告诉大家什么是列表 左侧的这一部分就可以称为是列表或者叫树,其实我们可以通过div+css实现列表,可是考虑语义化的问题,我们还是看看html提供好的列表标签,html提供了两种列表,一 ...

  10. linux_api之文件操作

    本篇索引: 1.引言 2.文件描述符 3.open函数 4.close函数 5.read函数 6.write函数 7.lseek函数 8.i/o效率问题 9.内核用以维护打开文件的相关数据结构 10. ...