简单数论(poj 1152)

Posted yoyo_sincerely

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单数论(poj 1152)相关的知识,希望对你有一定的参考价值。

题目: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)的主要内容,如果未能解决你的问题,请参考以下文章

PAT 数列的片段和简单数论

POJ2460 HDU1152 Brownie Points I水题

数论专题poj1061

#数论-模运算#POJ 115012842115

C. Neko does Maths(数论 二进制枚举因数)

[暑假集训--数论]poj2657 Comfort