UVa 568 Just the Facts (数论&打表&不打表)

本文介绍了一种计算任意非负整数阶乘后尾部第一个非零数字的方法。通过两种不同的算法实现:一种是预计算并存储结果的打表法;另一种是通过质因数分解计算的直接算法。这两种方法都能高效地解决UVa在线评测系统中的568号问题。

568 - Just the Facts

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=509

The expression N!, read as ``N factorial," denotes the product of the first N positive integers, where N is nonnegative. So, for example,

NN!
01
11
22
36
424
5120
103628800

For this problem, you are to write a program that can compute the last non-zero digit of any factorial for ($0 \le N \le 10000$). For example, if your program is asked to compute the last nonzero digit of 5!, your program should produce ``2" because 5! = 120, and 2 is the last nonzero digit of 120.

Input 

Input to the program is a series of nonnegative integers not exceeding 10000, each on its own line with no other letters, digits or spaces. For each integer  N , you should read the value and compute the last nonzero digit of  N !.

Output 

For each integer input, the program should print exactly one line of output. Each line of output should contain the value  N , right-justified in columns 1 through 5 with leading blanks, not leading zeroes. Columns 6 - 9 must contain ``  ->  " (space hyphen greater space). Column 10 must contain the single last non-zero digit of  N !.

Sample Input 

1
2
26
125
3125
9999

Sample Output 

    1 -> 1
    2 -> 2
   26 -> 4
  125 -> 8
 3125 -> 2
 9999 -> 8

方法1:打表。根据数据范围,计算时保留最后5位就行。

方法2:计算N!的素因子分解中5的幂的个数count,然后能被2整除的数要除以2直到达到count


先放上打表的算法:

/*0.016s*/

#include<cstdio>

int a[10001] = {1};/// 0!=1

int main()
{
	int i, x;
	for (i = 1; i <= 10000; i++)
	{
		a[i] = a[i - 1] * i;
		while (a[i] % 10 == 0) a[i] /= 10;
		a[i] %= 100000;///根据数据范围,保留最后5位就行~
	}
	while (~scanf("%d", &x))
		printf("%5d -> %d\n", x, a[x] % 10);
	return 0;
}

然后是不打表的算法:

/*0.016s*/

#include<cstdio>

int p[10000];

int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		int i, sum = 1, count = 0, tem = 0;
		if (n == 0)
		{
			printf("    0 -> 1\n");
			continue;
		}
		for (i = 0; i < n; i++) p[i] = i + 1;
		for (i = 0; i < n; i++)
			while (true)
			{
				if (p[i] % 5 == 0)
				{
					p[i] /= 5;
					count++;
				}
				else break;
			}
		for (i = 0; i < n; i++)
		{
			while (true)
			{
				if (p[i] % 2 == 0)
				{
					p[i] /= 2;
					tem++;
				}
				if (p[i] % 2 || tem == count)
					break;
			}
			if (tem == count)
				break;
		}
		for (i = 0; i < n; i++)
		{
			sum *= p[i];
			sum %= 10;
		}
		printf("%5d -> %d\n", n, sum);
	}
	return 0;
}

&lt;think&gt;我们正在解决IntelliJ IDEA中Java Web项目找Facts配置的问题。根据引用[2]和引用[4]的信息,Facts是IntelliJ IDEA特有的一个配置点,主要用于配置项目的框架,比如web.xml的位置以及Spring、Hibernate等框架的配置文件。如果找Facts,可能是因为项目没有被正确识别为Web模块或者配置有误。 解决方案步骤: 1. **确保项目已正确配置为Web模块**: - 打开项目配置:**File &gt; Project Structure**(或按Ctrl+Alt+Shift+S)。 - 在**Project Settings &gt; Modules**中,选择你的项目模块。 - 检查模块上是否有&ldquo;Web&rdquo;字样或者一个地球图标。如果没有,你需要添加Web框架支持。 2. **添加Web框架支持**: - 在Modules选项卡中,选中你的模块,点击上方的&ldquo;+&rdquo;号(Add)。 - 选择**Web**,然后点击OK。这样就会在该模块下创建一个Web配置。 3. **配置Facts**: - 在模块的配置中,你会看到右侧有一个**Facts**标签(在Sources、Paths等同级位置)。 - 点击**Facts**标签,在这里你可以看到Web相关的配置,特别是web.xml的路径(Deployment Descriptors)以及其他框架(如Spring、Hibernate)的配置。 - 如果web.xml的位置正确(比如由于从Eclipse导入导致位置同),你需要手动指定它。点击右侧的&ldquo;+&rdquo;号添加,然后浏览到你的web.xml文件(通常在WEB-INF目录下)[^4]。 4. **检查框架配置**: - 在Facts中,除了web.xml,你还可以添加其他框架(如Spring、Hibernate)。添加后,IntelliJ IDEA会在编辑区底部显示相应的配置工具,方便你管理这些框架的配置文件[^2]。 5. **应用更改并重启IDE(如果需要)**: - 完成配置后,点击OK保存。 - 如果仍然显示Facts,尝试**File &gt; Invalidate Caches / Restart...**来清除缓存并重启IDE。 6. **检查项目类型**: - 确保项目是一个Web项目(如使用了Jakarta EE、Servlet等)。如果项目是一个普通的Java项目,需要先转换为Web项目(通过添加Web框架支持,如步骤2)。 7. **重新导入项目(如果问题仍然存在)**: - 如果以上步骤无效,尝试重新导入项目。关闭当前项目,然后选择**File &gt; New &gt; Project from Existing Sources**,重新导入项目,并确保在导入过程中选择正确的项目类型(如Maven、Gradle或普通Java Web项目)[^5]。 总结:Facts配置在模块的Web框架下,如果模块没有添加Web支持,则会出现Facts标签。添加Web支持并正确配置web.xml和其他框架配置文件即可。 相关问题: 1. 如何在IntelliJ IDEA中正确配置Web模块? 2. IntelliJ IDEA中如何管理Spring框架的配置文件? 3. 导入Eclipse项目到IntelliJ IDEA需要注意哪些配置问题? &lt;/think&gt;在 IntelliJ IDEA 中解决 Java Web 项目找Facts 配置的问题,可按照以下步骤操作(基于引用内容分析): ### 解决方案步骤 1. **验证 Web 模块配置** - 打开 **File &gt; Project Structure &gt; Modules** - 选择您的 Web 模块,检查右侧是否有 **Web** 或 **Facts** 标签页 - 若存在,点击顶部 **+** 号添加 **Web** 框架支持(图1)[^2][^3] ```mermaid graph TD A[Project Structure] --&gt; B[Modules] B --&gt; C[选择模块] C --&gt; D[点击+号添加框架] D --&gt; E[选择Web] ``` 2. **手动指定 web.xml(关键步骤)** - 在 **Modules &gt; Web** 标签页中: - 定位 **Deployment Descriptors** 区域 - 点击 **+** 添加 web.xml 文件 - **手动浏览** 到项目中的 `WEB-INF/web.xml` 位置(图2)[^2][^4] - 由于 Eclipse 与 IDEA 路径规范同,需确保路径正确: ```plaintext 标准路径示例: YourProject/src/main/webapp/WEB-INF/web.xml (Maven) YourProject/web/WEB-INF/web.xml (传统项目) ``` 3. **检查框架事实配置** - 添加 web.xml 后,切换到 **Facts** 标签页 - 勾选已检测到的框架(如 Spring、Hibernate) - 若无自动识别,手动添加框架配置文件: - 点击 **+** 添加框架类型 - 指定
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值