• ZOJ


    In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (units). These are one type of 2-dimensional figurate numbers. The following picture shows how triangular numbers, square numbers, pentagonal numbers and hexagonal numbers represented as dots arranged in the shape of corresponding regular polygon.

    Polygonal Numbers: Triangular, Square, Pentagonal and Hexagonal numbers

    2016 is not only a leap year but also a triangular and hexagonal year. If you are patient enough, you can count the number of the dots in the left triangle or in the right hexagon in the following picture. The number of dots in each shape is 2016.

    2016 is a triangular-hexagonal-leap year

    Therefore, 2016 is a triangular-hexagonal-leap year. The previous triangular-hexagonal-leap year is 1540 and the next is 2556. So living to see 2016 is very rare experience.

    You task is to list the triangular-hexagonal-leap years from 2016 to 990528. 990528 is also a triangular-hexagonal-leap year.

    Input

    This problem has no input.

    Output

    Please print each triangular-hexagonal-leap year in increasing order.

    For example, if you are asked to list the triangular-hexagonal-leap years from 780 to 2556, the output should be:

    780
    1128
    1540
    2016
    2556
    

    Sample Output

    2016
    2556
    ...  <-- some lines are skipped
    990528
    思路:这道题对于我这个数学很不好的人来说,真的很骚,我冥思苦想,也想不出是这样一个思路。
    (三角形)2016 = 63*64/2,(六边形)2016 = 32*63,找在三角形和六边形中共同出现的那个数,用map存起来,再输出共同部分。
    #include <cstdio>
    #include <iostream>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <queue>
    #include <algorithm>
    #include <map>
    using namespace std;
    #define ll long long
    const int inf = 0xffffff;
    const int maxn = 1e6;
    bool cmp(int x)
    {
        if((x%4 == 0 && x%100 != 0) || (x%400 == 0))
            return 1;
        return 0;
    }
    int main()
    {
        map<int, int>a[2];
        for(int i = 63; i*(i+1) <= 990528*2; i++)//把三角形的n*(n+1)/2存起来
        {
            a[0][i*(i+1)/2] = 1;
        }
        for(int i = 32; i*(2*i-1) <= 990528; i++)//把六边形的n*(3*n-1)/2
        {
            a[1][i*(2*i-1)] = 1;
        }
        map<int, int>::iterator i;
        for(i = a[0].begin(); i != a[0].end(); i++)//找三角形和六边形共同出现的数字
            if(a[1][i->first] && cmp(i->first))
                printf("%d
    ", i->first);
        return 0;
    }

  • 相关阅读:
    EFCore.BulkExtensions Demo
    查询处理器用尽了内部资源,无法生成查询计划。这种情况很少出现,只有在查询极其复杂或引用了大量表或分区时才会出现。请简化查询。如果您认为该消息的出现纯属错误,请与客户支持服务部门联系,了解详细信息
    .net core 删除主表,同时删除子表
    java 数据类型优先级
    string.Join 的用法
    JDK-13下载安装及环境变量配置
    Java 前加加和后加加 总结
    变量类型查看-type
    路径:获取 & 更改
    用sql获取数据库中所有的表名、字段名
  • 原文地址:https://www.cnblogs.com/RootVount/p/10706011.html
Copyright © 2020-2023  润新知