UVa 471 Magic Numbers: Enumeration

Source: Internet
Author: User

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=412

Direct enumeration. In the code, we give a method of using bit arithmetic to judge whether there are any duplicates in the number.

Complete code:

01./*0.032s*/
.  
#include <cstdio>  
04.const long long maxn = 9876543210LL;  
06.inline bool Check (long long N)  
07.{  
L.    int i, cnt = 0;  
A. While    (n)  
.    {One  
.        i = 1 << (n%);        if (CNT & i) return false;        cnt |= i;        n/=;  
.    return true;  
.  
19.int Main ()  
20.{    long long s1, S2, N;    int t;    scanf ("%d", &t);  
While    (t--)  
.    {        scanf ("%lld", &n);  
For        (s2 = 1; s2 <= maxn; ++s2)  
.        {            s1 = n * S2;            if (S1 > Maxn) break;            if (check (S2) && check (S1)) printf ("%lld/%lld =%lld\n", s1, S2, n);  
.        if (t) Putchar (a);  
.    return 0;  
36.}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.