标签:printf task call first turn log clu 输出 应该
A number N is called a factorial number if it is the factorial of a positive integer. For example, the first few factorial numbers are 1, 2, 6, 24, 120, …
Given a number N, the task is to print all factorial numbers smaller than or equal to N.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains a number N as input.
Output:
For each test case, print all factorial numbers smaller than or equal to N in new line.
Constraints:
1<=T<=100
1<=N<=1018
Example:
Input:
2
2
6
Output:
1 2
1 2 6
下面是我的代码实现:
#include <stdio.h> #include <stdlib.h> int main() { int num,i; scanf("%d",&num); for(i=0;i<num;i++) { int N,j,temp=1; scanf("%d",&N); for(j=1;j<=N;j++) { temp=temp*j; if(temp<=N) printf("%d ",temp); } } return 0; }
这个程序现在还是错误的。因为我不确定输入的数值大小,只知道范围是:1<=T<=1001<=N<=1018,然后如果是最大的输入,这个输出是相当的大,那么这个应该是动态的,但是C里面怎么具体实现在输入都不确定的情况下,输出还是不确定的,我还没找到对应的关系。
如果换成C++语言,那直接就可以只用函数实现,C好难啊!
Find all factorial numbers less than or equal to N
标签:printf task call first turn log clu 输出 应该
原文地址:http://www.cnblogs.com/wongyi/p/7680074.html