UVA 725 Divisions 除法(暴力,0 ms)

本文提供了一段AC代码,用于解决一个特定的数学问题,通过使用位集和循环来查找满足条件的数字组合。代码使用了C++语言,并包含了标准输入输出、数学运算、位操作等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本题较为简单,将不会编写算法分析说明与代码编写指导。
AC 代码(0 ms):

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<bitset>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
bitset<10> appeared;
int main() {
	unsigned n, D; bool first = true, nosolution;
	for (;;) {
		scanf("%u", &n); if (n == 0)return 0;
		if (first == true)first = false;
		else putchar('\n');
		nosolution = true;
		for (unsigned d = max((unsigned)1234, 10000 / n);; ++d) {
			D = d * n; if (D > 98765)break;
			appeared.reset(); if (d < 10000)appeared[0] = 1;
			for (unsigned i = D; i != 0; i /= 10) { appeared[i % 10] = 1; }
			for (unsigned i = d; i != 0; i /= 10) { appeared[i % 10] = 1; }
			if (appeared.all() == true) { nosolution = false; printf("%u / %05u = %u\n", D, d, n); }
		}
		if (nosolution == true)printf("There are no solutions for %u.\n", n);
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值