ACM 编程 总结

来源:互联网 发布:大数据及其应用 编辑:程序博客网 时间:2024/06/14 05:44

(1)  Carmichael Numbers (110702)

/* Calculate b^e mod n */

int powmod(long long base, long long exp, long long m) {
    long long result = 1;
    
    while ( exp > 0 ) { 
        if ( (exp & 1) == 1 ) { 
            result = (result * base) % m;
        }   


        exp >>= 1;
    
        base = (base * base) % m;
    }   


    return result;
}


(2) Ones(110504)

n /* Input */

temp = 1;

while (temp % n)

        {   

    /* 1 -> 11 -> 111 -> 1111... */
            /* (temp * 10 + 1) mod n =
             *  ((temp mod n) * (10 mod n) + (1 mod n)) mod n */
            temp = (temp % n) * (10 % n) + 1;  
            x++;  
        }   


原创粉丝点击