zoukankan      html  css  js  c++  java
  • 2016(胡赛复现)_大数找规律

    Time Limit: 5 Sec  Memory Limit: 128 MB

    Description

     给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:
    1. 1≤a≤n,1≤b≤m;  2. a×b 是 2016 的倍数。

    Input

    输入包含不超过 30 组数据。
    每组数据包含两个整数 n,m (1≤n,m≤109).

    Output

    对于每组数据,输出一个整数表示满足条件的数量。

    Sample Input

    32 63
    2016 2016
    1000000000 1000000000
    

    Sample Output

    1
    30576
    7523146895502644

    【思路】判定((n%2016)*(m%2016))%2016==0

    找规律归类 

    将n、m分离:对他们分别做商k、取余ret,开两个数组,数组的前ret位为k+1,其余为k,记录有多少组1~2016;

    再跑两遍for循环到2016,(i*j)%2016==0时,加上a[i]*b[j];

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    using namespace std;
    long long a[2050],b[2050];
    int main()
    {
        long long n,m;
        while(~scanf("%lld%lld",&n,&m))
        {
            long long k,ret;
            k=n/2016;//分离n;
            ret=n%2016;
            for(int i=1;i<=ret;i++)
            {
                a[i]=k+1;
            }
            for(int i=ret+1;i<=2016;i++)
            {
                a[i]=k;
            }
            k=m/2016;//分离m;
            ret=m%2016;
            for(int i=1;i<=ret;i++)
                b[i]=k+1;
            for(int i=ret+1;i<=2016;i++)
                b[i]=k;
            long long cnt=0;
            for(int i=1;i<=2016;i++)
            {
                for(int j=1;j<=2016;j++)
                {
                    if((i*j)%2016==0)
                        cnt+=a[i]*b[j];
                }
            }
            cout<<cnt<<endl;
        }
        return 0;
    }
  • 相关阅读:
    python模块学习第 0000 题
    报错The VMware Authorization Service is not running
    图像指纹的重复识别
    CSS预编译器配置-------LESS Sass Stylus webstorm
    CSS布局中的水平垂直居中
    进度与日程
    HTML5 application cache
    进度
    CC2530芯片介绍
    Linux命令工具 top详解
  • 原文地址:https://www.cnblogs.com/iwantstrong/p/5837972.html
Copyright © 2011-2022 走看看