zoukankan      html  css  js  c++  java
  • 数学--数论-- HDU -- 2854 Central Meridian Number (暴力打表)

    A Central Meridian (ACM) Number N is a positive integer satisfies that given two positive integers A and B, and among A, B and N, we have
    N | ((A^2)*B+1) Then N | (A^2+B)
    Now, here is a number x, you need to tell me if it is ACM number or not.

    Input

    The first line there is a number T (0<T<5000), denoting the test case number.
    The following T lines for each line there is a positive number N (0<N<5000) you need to judge.

    Output

    For each case, output “YES” if the given number is Kitty Number, “NO” if it is not.

    Sample Input

    2
    3
    7
    Sample Output

    YES
    NO
    Hint
    X | Y means X is a factor of Y, for example 3 | 9;
    X^2 means X multiplies itself, for example 3^2 = 9;
    XY means X multiplies Y, for example 33 = 9.

    题意:

    给你一个数,如果能找出两个数a,b使得这三个数满足式子1,但不满足式子2,那么这个数n就不是符合要求的数,输出NO

    思路:
    实在算不粗来了,把我写的代码打了个表,然后,发现最大是240,然后其他,就没其他了。

    #include <cstring>
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <map>
    using namespace std;
    int mp[10000000];
    int main()
    {
        mp[1] = 1;
        mp[2] = 1;
        mp[3] = 1;
        mp[4] = 1;
        mp[5] = 1;
        mp[6] = 1;
        mp[8] = 1;
        mp[10] = 1;
        mp[12] = 1;
        mp[15] = 1;
        mp[16] = 1;
        mp[20] = 1;
        mp[24] = 1;
        mp[30] = 1;
        mp[40] = 1;
        mp[48] = 1;
        mp[60] = 1;
        mp[80] = 1;
        mp[120] = 1;
        mp[240] = 1;
        int T, a;
        cin >> T;
        while (T--)
        {
            scanf("%d", &a);
            if (mp[a] == 1)
                puts("YES");
            else
                puts("NO");
        }
        return 0;
    }
    

    达标代码

    
    #include <iostream>
    #include <cstdio>
    using namespace std;
    int mp[10000000];
    
    int ok(int x)
    {
        for (int i = 1; i <= 1000; i++)
        {
            for (int j = 1; j <= 1000; j++)
            {
                if ((i * i * j + 1) % x == 0 && ((i * i + j) % x != 0))
                    return 0;
            }
        }
        return 1;
    }
    int main()
    {
        for (int i = 1; i <= 1000; i++) //打表部分
        {
            if (ok(i))
            {
                printf("mp[%d]=1; 
    ", i);
            }
        }
    }
    
  • 相关阅读:
    统计 (Standard IO)
    存储过程中的错误处理
    簡單SQL存儲過程實例
    SQLSERVER存储过程基本语法
    SQL Server游标的使用【转】
    实现业务系统中的用户权限管理--实现篇
    实现业务系统中的用户权限管理--设计篇
    C#.net 微信公众账号接口开发
    jquery select radio
    asp.net Repeater使用例子,包括分页
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/12798496.html
Copyright © 2011-2022 走看看