设为首页 加入收藏

TOP

UVA471- Magic Numbers
2015-07-20 17:56:15 来源: 作者: 【 】 浏览:5
Tags:UVA471- Magic Numbers

题目链接


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

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

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        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; }
      
     
    
   
  


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UVA 10986 Sending email(SPFA) 下一篇POJ 1006 生理周期

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: