注册 登录
编程论坛 新人交流区

[求助] 10的1000000方怎么弄?

karon1988 发布于 2007-11-01 17:49, 789 次点击
题目:
Problem description

We are not alone.

In the year 3000, scientists have eventually found another planet which has intelligent being living on. Let's say, Planet X. And we call the intelligent being there ‘XMen'. To learn advanced technology from Planet X, we want to exchange information with XMen. Unfortunately, XMen use a very strange data format when sending message, which is called m-encoding (m is for multiplication). Scientists on earth have successfully found out the algorithm of m-encoding, defining as following:

For each data package from XMen, there are two non-negative integer numbers, A and B. And the actual data XMen want to send is the product of A and B (A * B).

So, in this problem, you are to implement a decoder for data packages from XMen.

Input
There are multiple test cases. Input data starts with an integer N, indicating the number of test cases.

Each test case occupies just one line, and contains two non-negative integers A and B (0 <= A, B <= 101000000), separated by just one space.

Output
For each test case, output the actual data XMen want to send, one in a line.

Sample Input
3
1 1
100 123
12345678901234567890 54321
Sample Output
1
12300
670629623593962962352690

那个10 的1000000次方太大了点吧....怎么办?
8 回复
#2
manm2007-11-01 17:54
怎么全是英文哦  看不懂呢!  汗!
#3
karon19882007-11-01 18:09
主要就是想知道那个那么大的数怎么表示呢?
#4
zhouwh2007-11-02 08:45

是不是可以用科学计数法啊

#5
lctt2007-11-02 08:57
................
#6
nghf2007-11-02 11:43

用大数表示吧,我只知道大数相乘.

#7
visolleon2007-11-02 15:19
两个超大的数字相乘的程序:

[CODE]
using System;
using System.Collections.Generic;
using System.Text;

namespace BigNumber
{
class Program
{
static void Main(string[] args)
{
Console.Write("Number A is : ");
string Aa = Console.ReadLine();
int[] A = new int[Aa.Length];
for (int i = 0; i < Aa.Length; i++)
{
A[Aa.Length-1-i] = Convert.ToInt32(Aa.Substring(i, 1));
//Console.WriteLine(A[Aa.Length - 1 - i]);
}

Console.Write("Number B is : ");
string Bb = Console.ReadLine();
int[] B = new int[Bb.Length];
for (int i = 0; i < Bb.Length; i++)
{
B[Bb.Length-1-i] = Convert.ToInt32(Bb.Substring(i, 1));
//Console.WriteLine(B[Bb.Length - 1 - i]);
}
int[,] sum = new int[Aa.Length,Bb.Length];
int[] wsum = new int[Aa.Length + Bb.Length];
for (int i = 0; i < Aa.Length; i++)
{
for (int j = 0; j < Bb.Length; j++)
{
sum[i,j] = A[i]*B[j];
wsum[i + j] = wsum[i + j] + sum[i, j];
if (wsum[i + j].ToString().Length > 1)
{
wsum[i + j + 1] = wsum[i + j + 1] + wsum[i + j]/10;
wsum[i + j] = Convert.ToInt32(wsum[i + j].ToString().Substring(1, 1));
}
Console.WriteLine("sum[" + i + "," + j + "] = {0}", sum[i, j]);
}
}
string end = "";
for (int m = 0; m < Aa.Length + Bb.Length; m++)
{
Console.WriteLine("wsum[" + m + "] = {0}", wsum[m]);
end = wsum[m].ToString() + end;
}
Console.WriteLine();
Console.WriteLine("================================================================");
Console.WriteLine("计算结果为:{0}",end);
Console.ReadLine();
}
}
}

[/CODE]
#8
visolleon2007-11-02 15:21
如果需要判断该数是否大于10的1000000次方的话,就将该数字ToString(),然后判断它的Length的长度是否大于1000000
#9
zhqifshy2007-11-02 17:46
在java上可以直接用Math.pow(),但值太大的话就要注意变量类型
long num = (long)Math.pow(10, 1000000);
1