emu in blogjava

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  171 随笔 :: 103 文章 :: 1052 评论 :: 2 Trackbacks

Problem Statement

    

In the factorial number system the value of the first digit (from the right) is 1!, the value of the second digit is 2!, ..., and the value of the n-th digit is n!. This means that any decimal number d can be written in this system as: anan-1...a2a1, where

d = an * n! + an-1 * (n-1)! + ... + a2 * 2! + a1 * 1! and 0 <= ai <= i for all i.

Given an int num in decimal, return its representation in the factorial number system.

Definition

    
Class: FactorialSystem
Method: convert
Parameters: int
Returns: int
Method signature: int convert(int num)
(be sure your method is public)
    

Notes

- n! = 1 * 2 * ... * n

Constraints

- num will be between 1 and 3628799 (10!-1), inclusive.

Examples

0)
    
1
Returns: 1
1)
    
24
Returns: 1000
24 = 4!
2)
    
153
Returns: 11111
153 = 1! + 2! + 3! + 4! + 5!.
3)
    
133
Returns: 10201
4)
    
3628799
Returns: 987654321
Largest possible input.

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

posted on 2005-12-23 10:26 emu 阅读(1278) 评论(4)  编辑  收藏 所属分类: google编程大赛模拟题及入围赛真题

评论

# re: FactorialSystem (code jam china round2 300分真题) 2006-07-28 08:29 peng he
#include<stdio.h>
void main()
{int i, a;
scanf("%d",&a);
for(i=2;a/i!=0;i++)
{printf("%d",a%i);
a=a/i;



}


}  回复  更多评论
  

# re: FactorialSystem (code jam china round2 300分真题) 2007-06-09 15:39 匿名
@peng he
你这编的什么东西呀

题目意思理解清楚没有呀  回复  更多评论
  

# re: FactorialSystem (code jam china round2 300分真题)[未登录] 2007-09-08 22:44 a
package factorial;
import java.util.LinkedList;
public class Factorial {

public static void main(String[] args) {
StringBuffer sb=new StringBuffer();
LinkedList<Integer> al=new LinkedList<Integer>();
int m=445;
int z=1;
int fZ=z;
al.add(fZ);
while(m/fZ>0)
{
z++;
al.addLast(al.getLast()*z);
fZ=al.getLast();

}
int n=z-1;
for(int i=n;i>=1;i--)
{

int temp=m/al.get(i-1);
m-=temp*al.get(i-1);
sb.append(temp);
}
System.out.println(sb.toString());

}

}
  回复  更多评论
  

# re: FactorialSystem (code jam china round2 300分真题) 2008-10-12 21:45 zgqchina
#include<iostream>
using namespace std;

long factrial(int n) //求阶乘,n>0
{
if(n==1) return 1;
else
return n*factrial(n-1);
}

int k=0,a[9]; //全局变量 K用来计数,数组用来存放数列

void convert(double num) //转换成数列
{
int n=9;
while((num>0)&&(n>=1))
{
int m=factrial(n);
if(num<m)
a[k]=0;
else
{
for(int p=n;p>=1;p--)
if(num>=p*m)
{
a[k]=p;
break;
}
num=num-p*m;
}
n--;
k++;
}
}

void main()
{
cout<<"please input a number(num will be between 1 and 3628799) :"<<endl;
double temp;
cin>>temp;
cout<<"now the result is :"<<endl;
convert(temp);
int i=0;
while(a[i]==0) i++;
for(i;i<9;i++)
cout<<a[i]<<" ";
}  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: