zoukankan      html  css  js  c++  java
  • UVA 294

    Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an interesting number, since it is the first odd number for which the sum of its divisors is larger than the number itself.

    To help them search for interesting numbers, you are to write a program that scans a range of numbers and determines the number that has the largest number of divisors in the range. Unfortunately, the size of the numbers, and the size of the range is such that a too simple-minded approach may take too much time to run. So make sure that your algorithm is clever enough to cope with the largest possible range in just a few seconds.

    The first line of input specifies the number N of ranges, and each of the N following lines contains a range, consisting of a lower bound Land an upper bound U, where L and U are included in the range. L and U are chosen such that tex2html_wrap_inline42 and tex2html_wrap_inline44 .

    For each range, find the number P which has the largest number of divisors (if several numbers tie for first place, select the lowest), and the number of positive divisors D of P (where P is included as a divisor). Print the text 'Between L and HP has a maximum of Ddivisors.', where LHP, and D are the numbers as defined above.

    3
    1 10
    1000 1000
    999999900 1000000000
    Between 1 and 10, 6 has a maximum of 4 divisors.
    Between 1000 and 1000, 1000 has a maximum of 16 divisors.
    Between 999999900 and 1000000000, 999999924 has a maximum of 192 divisors.



    题意:给你 a,b,让你找出 a,b之间因子最多的数是多少 b-a《=1000 我们枚举就好了
    //meek
    #include<bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include<map>
    #include<queue>
    using namespace std ;
    typedef long long ll;
    #define mem(a) memset(a,0,sizeof(a))
    #define pb push_back
    #define fi first
    #define se second
    #define MP make_pair
    
    const int N=550;
    const ll INF = 1ll<<61;
    const int inf = 1000000007;
    const int MOD =   2000000011;
    
    
    ll cal(ll x) {
        ll hav = 0;
       for(ll i = 1; i*i <= x; i++) {
        if(x % i == 0) hav ++;
        if(x % i == 0 && x / i != i) hav++;
       }
       return hav;
    }
    int main() {
        int T;
        ll a,b,ans,tmp;
        scanf("%d",&T);
        while(T--) {
            ans = -1;
            scanf("%lld%lld",&a,&b);
            for(ll i = a; i <= b; i++) {
                ll temp = cal( i );
                if(temp > ans) {
                    ans = temp;
                    tmp = i;
                }
            }
            printf("Between %lld and %lld, %lld has a maximum of %lld divisors.
    ",a,b,tmp,ans);
        }
        return 0;
    }
    代码
  • 相关阅读:
    如何设置nginx日志格式来查看负载分担结果
    Nginx缓存使用官方教程及常见问题解答
    nginx缓存和flask_cache
    flask_wtf/wtforms几个坑点,先简单记此
    maven-dependency-plugin插件的使用
    maven+jenkins+jmeter性能测试:maven把项目依赖拷贝到项目指定位置
    sudo:抱歉,您必须拥有一个终端来执行 sudo 解决办法;ssh执行sudo命令的方法;给用户增加sudo免密权限
    innerHTML引起IE的内存泄漏
    innerHTML与IE浏览器内存泄露问题
    IE内存泄露与无法回收研究小结
  • 原文地址:https://www.cnblogs.com/zxhl/p/5104001.html
Copyright © 2011-2022 走看看