hdu 2462数论

这题考查的内容还是比较多的,不过仅限于思路,如果模板准备充足的话还是很快的。

这题首先要对问题进行转换。题目是给一个L,问由8组成的最短的能被L整除的数。不妨设长度为x。那么就是要求最小的x使8*[1+10+10^2+...+10^(x-1)] ≡ 0 (mod L)。

也就是求最小的x使(8/9)*(10^x-1) ≡ 0 (mod L)。也就是求最小的x使10^x ≡ 1 (mod y),其中y = 9 * L / gcd(8, 9 * L)。于是存在满足题意的x当且仅当gcd(10, y) = 1。

对于有解的情况,显然,x = φ(y)时,10^φ(y) ≡ 1 (mod y)成立,且每个符合条件的x都满足x|φ(y)。所以求出φ(y)的所有约数,从小到大试一试就得出结果了。用到的模板还是挺多的。

/*
 * hdu3079/win.cpp
 * Created on: 2012-11-4
 * Author    : ben
 */
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
map<char, char> mymap;
void init() {
    char vowels[] = "aoeiu";
    char vowels2[] = "AOEIU";
    char consonant[] = "bcdfghjklmnpqrstvwxyz";
    char consonant2[] = "BCDFGHJKLMNPQRSTVWXYZ";
    for(int i = 0; i < 5; i++) {
        mymap[vowels[i]] = vowels2[i];
        mymap[vowels2[i]] = vowels2[i];
    }
    for(int i = 0; i < 21; i++) {
        mymap[consonant2[i]] = consonant[i];
        mymap[consonant[i]] = consonant[i];
    }
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
#endif
    int T, len;
    char str[200];
    init();
    scanf("%d", &T);
    getchar();
    while(T--) {
        gets(str);
        len = strlen(str);
        for(int i = 0; i < len; i++) {
            str[i] = mymap[str[i]];
        }
        puts(str);
    }
    return 0;
}

 

posted @ 2012-11-04 17:39  moonbay  阅读(227)  评论(0编辑  收藏  举报