1. ACM UVA-10325

    題目

    int M[15];
    unsigned long long nn,m;
    unsigned long long gcd(unsigned long long a,unsigned long long b ){
        return b == 0?a:gcd(b,a%b);
    }
    unsigned long long lcm(unsigned long long a,unsigned long long b){
        return (a*b)/(gcd(a,b));
    }
    unsigned long long ...

    Read more...


  2. ACM UVA-10407

    gcd

    n1 = d1*q1+r1

    n2 = d1Xq2+r1

    n3 = d1Xq3+r1

    要找出d1出來

    a1= n1-n2 = d1X(q1-q2)

    a2 = n1-n3 = d1X(q1-q3)

    只要找出a1跟a2的最大公因數即可求出

    如果只有兩個呢?

    a1 = (n1-n2)X1 = d1X(q1-q2)

    那麼n1-n2自然就是最大的那一個答案了。

    int gcd(int a,int b){
        return b == 0?a:gcd(b,a%b);
    
    }
    int main(int argc, char const* argv[])
    {
        string ...

    Read more...


  3. ACM UVA-10591

    快樂數

    #define happy 1
    #define unhappy 2
    int main(int argc, char const* argv[])
    {
        //1000000000
        //999999999
        //81*9 = 729
        int n[730] = {0}  ;
        n[1] = happy;
        for(int i = 2;i<= 729;i++){ 
            if(n[i]){
                continue;
            }
            set<int> tmp;
            tmp.insert(i);
            int sum = 0;
            int g = i;
            bool ...

    Read more...


  4. ACM UVA-10611

    binary Search

    int N[50005];
    void binarySearch(int search,int n){
        int left = 0,right = n-1;
        while(left <= right){
            int mid = (left+right)/2;
            if(N[mid]<search){
                left = mid+1;
            }else if(N[mid]>search){
                right = mid-1;
            }else if(N[mid] == search){
                if(mid+1>n-1 ...

    Read more...


  5. ACM UVA-10622

    Prime+GCD

    int gcd(int a,int b){
        return b == 0?a:gcd(b,a%b);
    }
    int main(int argc, char const* argv[])
    {
        bool prime[65540];
        long long ppp[65540];
        int power[65540];
        int m = 0;
        for(long long i = 2;i<65540;i++){
            if(!prime[i]){
                ppp[m++] = i ...

    Read more...


  6. ACM UVA-10673

    暴力法

    int main(int argc, char const* argv[])
    {
        int t;
        while(scanf("%d",&t) != EOF){
            while(t--){
                unsigned long long x,k;
                scanf("%llu %llu",&x,&k);
                int a = floor((double)x/k);
                int b = ceil((double)x/k);
                unsigned long long p;
                unsigned long long q;
                bool ans = false ...

    Read more...


  7. ACM UVA-10696

    f91

    int f91(int N){
        if(N >= 101){
            return N-10;
        }
        if(N <= 100){
            return f91(f91(N+11));
        }
    }
    int main(int argc, char const* argv[])
    {
        int n;
        while(scanf("%d",&n) && n != 0){
            printf("f91(%d) = %d\n",n,f91(n));
        }
    
        return 0;
    }
    

    Read more...


  8. ACM UVA-10699

    prime

    int main(int argc, char const* argv[])
    {
        int n;
        while(~scanf("%d",&n) && n != 0){
            int nn = sqrt(n);
            int count = 0;
            int k = n;
            for(int i = 2;i<= nn;i++){
                if(n%i == 0){
                    while(n%i == 0) {
                        n = n/i;
                    }
                    count++;
                }
            }
            if(n>1){
                count++;
            }
            n ...

    Read more...


  9. ACM UVA-10783

    prime

    int main(int argc, char const* argv[])
    {
        bool prime[2001]; 
        prime[0] = true;
        prime[1] = true;
    
        for(int i = 2;i<2001;i++){
            if(!prime[i]){
                for(int j = i*i;j<2001;j = j+i){
                    prime[j] =true;
                }
            }
        }
        int p;
    
        char str[2001];
        while(scanf("%d",&p) != EOF ...

    Read more...


  10. ACM UVA-10892

    dp

    #define MAX 500001
    int N[MAX];
    int solution(int n){
    
        if(N[n])
            return N[n];
    
        if(n % 2 == 0){
            N[n] = solution(n/2)*2;
        }
        else{
            N[n] = (solution((n+1)/2)-1)*2;
        }
    
        return N[n];
    
    }
    int main(int argc, char const* argv[])
    {
        int n;
        N[1 ...

    Read more...


« Page 10 / 13 »