UVA471- Magic Numbers

来源:互联网 发布:域名信息备案查询系统 编辑:程序博客网 时间:2024/05/22 00:39

题目链接


题意:s1/s2=N,s1、s2、N都是各个位数上数字不相同的整数。给定N,求有多少个这样的式子并输出。

思路:其实最大的数只能是9876543210,所以我们只要暴力枚举,枚举过程中判断s1、s2是否符合题目要求。

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>using namespace std;typedef long long ll;const ll MAXN = 9876543210;ll ans, n;int vis[100];int judge(ll x) {    memset(vis, 0, sizeof(vis));    while (x) {        int temp = x % 10;        if (vis[temp])            return false;        vis[temp] = 1;          x /= 10;     }    return true;}int main() {    int cas;    scanf("%d", &cas);    for (int i = 0; i < cas; i++) {        if (i)             printf("\n");        scanf("%lld", &n);        for (ll i = 1; i <= MAXN; i++) {            ans = i * n;            if (ans > MAXN)                break;            if (judge(ans) && judge(i))                printf("%lld / %lld = %lld\n", ans, i, n);        }    }    return 0;}


0 0
原创粉丝点击