zoukankan      html  css  js  c++  java
  • hdu 5108 Alexandra and Prime Numbers(水题 / 数论)

    题意:

    给一个正整数N,找最小的M,使得N可以整除M,且N/M是质数。

    数据范围:

    There are multiple test cases (no more than 1,000). Each case contains only one positive integer N.
    N1,000,000,000.
    Number of cases with N>1,000,000 is no more than 100.

    思路:

    N=M*prime     故必有M或prime小于等于sqrt(N)。暴力扫一遍就行,,总共要扫两次(其实扫一遍也行,,,,)

    *:bestCoder第一题竟然TLE了,,,跪了,,,爆零啊!

    代码:

    int N;
    
    bool isPrime(int x){
        int m=(int)sqrt(x+0.5);
        rep(i,2,m) if(x%i==0) return false;
        return true;
    }
    
    int main(){
        while(scanf("%d",&N)!=EOF){
            if(N<2){
                puts("0");
                continue;
            }
            int m=(int)sqrt(N+0.5);
            int maxs=-1;
            rep(i,1,m) if(N%i==0 && isPrime(N/i)){
                maxs=(N/i);
                break;
            }
            rep2(i,m,1) if(N%i==0 && isPrime(i)){
                maxs=max(maxs,i);
                break;
            }
            printf("%d
    ",N/maxs);
        }
    }
  • 相关阅读:
    初中几何
    角平分线导致的三角形内外角关系
    解方程
    初中|数学题目整理
    求一次函数解析式
    整式的四则运算
    分式方程
    做辅助线的方法
    线段相等的证明思路
    python2.7安装sqlite3模块
  • 原文地址:https://www.cnblogs.com/fish7/p/4115940.html
Copyright © 2011-2022 走看看