Description

Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up with a new one, called Sama’s triangle (some of you may be familiar with this name).

       In this triangle, there is only 30 row, and the ith row has i-1 number, f[i][1] , f[i][2], …, f[i][i-1] (1strow has no number). And initially, f[i][0] = a, f[i][i] = b, (0<a, b) then f[i][j] = f[i-1][j-1] + f[i-1][j] (for all i from 1 to 30 , for all j in 1 to i-1, inclusive).
       2ndrow    f[2][1]
       3rdrow     f[3][1]     f[3][2]
       4throw     f[4][1]     f[4][2]     f[4][3]
       30throw   f[30][1]   f[30][2]   f[30][3]   …    f[30][29]
       Now the teacher asked, ‘how many M are in the triangles among all pairs of (a, b).

Input

The input consists of several test cases.
The first line consists of one integer T (T <= 500), meaning the number of test cases.
For each test cases, there is one integer M (M<= 1e9), which is asked from the teacher.
Here, 1eX means 1000…0000 (x 0s).

Output

For each test case, output the times number M shows up in all positions of all triangles.

Sample Input

1
3

Sample Output

4

每个位置的数可以用一个二元一次函数表示

武大OJ 613. Count in Sama’s triangle的更多相关文章

  1. LeetCode OJ 222. Count Complete Tree Nodes

    Total Accepted: 32628 Total Submissions: 129569 Difficulty: Medium Given a complete binary tree, cou ...

  2. LeetCode OJ:Count Primes(质数计数)

    Count the number of prime numbers less than a non-negative number, n. 计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如 ...

  3. LeetCode OJ:Count Complete Tree Nodes(完全二叉树的节点数目)

    Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...

  4. LeetCode OJ:Count and Say(数数)

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  5. 武大OJ 612. Catch the sheep

    Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, tou ...

  6. 武大OJ 574. K-th smallest

    Description Give you a number S of length n,you can choose a position and remove the number on it.Af ...

  7. 武大OJ 622. Symmetrical

    Description          Cyy likes something symmetrical, and Han Move likes something circular. Han Mov ...

  8. 武大OJ 706.Farm

    Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made ...

  9. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

随机推荐

  1. daily_journal_3 the game of thrones

    昨晚追完了最爱的美剧(the game of thrones),哇,看到结局有点崩溃.果然还是美帝淫民开放,各种乱伦,在七夕收到的万点暴击就祝天下有情人就像剧中一样终是血亲. 昨天算是完成了git的复 ...

  2. CentOS6.5磁盘分区和挂载操作记录

    CentOS6.5磁盘分区和挂载操作记录. [root@CentOS ~]# fdisk -l Disk /dev/sda: bytes heads, sectors/track, cylinders ...

  3. 用Movie显示gif(1)SimpleGif

    代码如下: import android.content.Context; import android.graphics.Canvas; import android.graphics.Movie; ...

  4. ora-00600 to check

    Hi , Let us know issue reproducibility executing following statement from command prompt: SELECT &qu ...

  5. keystore找回密码

    昨天准备给自己的应用发布一个新版本,在apk打包时,发现之前的用的keystore密码忘了. 蛋碎了一地,我把我所能想到的密码都试了一遍(注:我平常在各个门户网站注册基本上用的都是那几个字母和数字组合 ...

  6. Android RxJava1.X升级到RxJava2.X笔记

    简书地址 http://www.jianshu.com/p/2badfbb3a33b 描述 RxJava 1.X RxJava 2.X package包名 rx.xxx io.reactivex.xx ...

  7. MySQL的基本概念与操作

    数据库的基本概念什么是数据库?用于存储和管理数据的仓库.数据库的特点:持久化存储数据的.其实数据库就是一个文件系统方便存储和管理数据使用了统一的方式操作数据库 – SQL数据库的分类:数据库根据存储采 ...

  8. luogu P3899 [湖南集训]谈笑风生 线段树合并

    Code: #include<bits/stdc++.h> #define maxn 300002 #define ll long long using namespace std; vo ...

  9. jQuey中的return false作用是什么?

    jQuey中的return false作用是什么?在众多的语句中都有return false的使用,当然对于熟悉它的开发者来说,当然是知根知底,知道此语句的作用,当然也就知道在什么时候使用此语句,不过 ...

  10. 洛谷——P4296 [AHOI2007]密码箱

    P4296 [AHOI2007]密码箱 密码x大于等于0,且小于n,而x的平方除以n,得到的余数为1. 求这个密码,$1<=n<=2,000,000,000$ 暴力枚举,数据有点儿水$O( ...