码迷,mamicode.com
首页 > 其他好文 > 详细

简单数论(poj 1152)

时间:2016-03-20 21:10:43      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

题目:An Easy Problem!

题意:求给出数的最小进制。

思路:暴力WA;

discuss中的idea:

给出数ABCD,若存在n 满足   (A* n^3 +B*n^2+C*n^1+D*n^0)%(n-1) == 0

则((A* n^3)%(n-1) +(B*n^2)%(n-1)+(C*n^1)%(n-1)+D%(n-1))%(n-1) == 0

                                    (A+B+C+D)%(n-1) == 0

NB!

是时候深入的看下数论了;

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>

#define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 50005
const double PI = acos(-1.0);
typedef long long LL ;


int cal(char x){
    if(x >= 0 && x <= 9)
        return x - 0;
    else if(x >= A && x <= Z)
        return x - A +10;
    else if(x >= a && x <= z)
        return x - a +36;
    return 0;
}
string s;
int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>s){
        int n = s.size();
        int maxn = 0,sum = 0;
        for(int i = 0;i < n;i++){
            sum +=cal(s[i]);
            maxn = max(maxn, cal(s[i]));
        }
        int  flag = 1;
        for(int i = maxn+1; i <= 62; i++)
            if(sum%(i-1) == 0){
                printf("%d\n",i);
                flag = 0;
                break;
            }
        if(flag)
            printf("such number is impossible!\n");
    }
    return 0;
}

 

简单数论(poj 1152)

标签:

原文地址:http://www.cnblogs.com/yoyo-sincerely/p/5299275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!