题目: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!

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

模运算法则:

模运算与基本四则运算有些相似,但是除法例外。其规则如下:
(a + b) % p = (a % p + b % p) % p    (1)
(a - b) % p = (a % p - b % p) % p    (2)
(a * b) % p = (a % p * b % p) % p     (3)
(a^b) % p = ((a % p)^b) % p       (4)
推论:
若a≡b (% p),则对于任意的c,都有(a + c) ≡ (b + c) (%p);                               (10)
若a≡b (% p),则对于任意的c,都有(a * c) ≡ (b * c) (%p);                                (11)
若a≡b (% p),c≡d (% p),则 (a + c) ≡ (b + d) (%p),(a - c) ≡ (b - d) (%p),
(a * c) ≡ (b * d) (%p),(a / c) ≡ (b / d) (%p);                                              (12)
 

费马定理:

    若p是素数,a是正整数且不能被p整除,则:a^(p-1) mod p = 1 mod p

推论:

    若p是素数,a是正整数且不能被p整除,则:a^p mod p = a mod p
 
 
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <string>
  8. #include <cstring>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <set>
  13.  
  14. #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
  15. #define INF 0x3f3f3f3f
  16. #define INFL 0x3f3f3f3f3f3f3f3f
  17. #define zero_(x,y) memset(x , y , sizeof(x))
  18. #define zero(x) memset(x , 0 , sizeof(x))
  19. #define MAX(x) memset(x , 0x3f ,sizeof(x))
  20. #define swa(x,y) {LL s;s=x;x=y;y=s;}
  21. using namespace std ;
  22. #define N 50005
  23. const double PI = acos(-1.0);
  24. typedef long long LL ;
  25.  
  26. int cal(char x){
  27. if(x >= '' && x <= '')
  28. return x - '';
  29. else if(x >= 'A' && x <= 'Z')
  30. return x - 'A' +;
  31. else if(x >= 'a' && x <= 'z')
  32. return x - 'a' +;
  33. return ;
  34. }
  35. string s;
  36. int main(){
  37. //freopen("in.txt","r",stdin);
  38. //freopen("out.txt","w",stdout);
  39. while(cin>>s){
  40. int n = s.size();
  41. int maxn = ,sum = ;
  42. for(int i = ;i < n;i++){
  43. sum +=cal(s[i]);
  44. maxn = max(maxn, cal(s[i]));
  45. }
  46. int flag = ;
  47. for(int i = maxn+; i <= ; i++)
  48. if(sum%(i-) == ){
  49. printf("%d\n",i);
  50. flag = ;
  51. break;
  52. }
  53. if(flag)
  54. printf("such number is impossible!\n");
  55. }
  56. return ;
  57. }

数论 : 模运算法则(poj 1152)的更多相关文章

  1. #数论-模运算#POJ 1150、1284、2115

    1.POJ 1150 The Last Non-zero Digit #质因数分解+模运算分治# 先贴两份题解: http://www.hankcs.com/program/algorithm/poj ...

  2. HDU——1395 2^x mod n = 1(取模运算法则)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

  4. poj 3980 取模运算

    取模运算 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10931   Accepted: 6618 Description ...

  5. java 取模运算% 实则取余 简述 例子 应用在数据库分库分表

    java 取模运算%  实则取余 简述 例子 应用在数据库分库分表 取模运算 求模运算与求余运算不同.“模”是“Mod”的音译,模运算多应用于程序编写中. Mod的含义为求余.模运算在数论和程序设计中 ...

  6. a ^ b mod c 取模运算优化反思(老物)

    这是一篇嘲讽我之前的自己采用笨重愚蠢思想去解决问题的日志. RSA 加密与解密涉及到 a ^ b mod c 的问题,如何计算这个值呢? 我会选择 pow(a, b) % c, 事实上在写RSA的时候 ...

  7. mysql中的优化, 简单的说了一下垂直分表, 水平分表(有几种模运算),读写分离.

    一.mysql中的优化 where语句的优化 1.尽量避免在 where 子句中对字段进行表达式操作select id from uinfo_jifen where jifen/60 > 100 ...

  8. c++ 模运算

    在数学里,"模运算"也叫"求余运算",用mod来表示模运算. 对于 a mod b 可以表示为 a = q(商)*b(模数) + r(余数),其中q表示商,b表 ...

  9. 二分求幂/快速幂取模运算——root(N,k)

    二分求幂 int getMi(int a,int b) { ; ) { //当二进制位k位为1时,需要累乘a的2^k次方,然后用ans保存 == ) { ans *= a; } a *= a; b / ...

随机推荐

  1. 【javascript基础】7、继承

    前言 由于本人水平有限,所以有些高手觉得现在写的内容偏容易,要一点点来嘛,今天和大家学习或者复习一下javascript的继承.我也就是尽量写吧······ 继承 javascript的继承其实主要就 ...

  2. NSIS打包(一)常用概念简介

    1.NSIS简介 官网:http://sourceforge.net/projects/nsis/ 维基百科: http://zh.wikipedia.org/wiki/Nullsoft%E8%85% ...

  3. goldengate 参数之GETTRUNCATES | IGNORETRUNCATES --转载

    GETTRUNCATES | IGNORETRUNCATESValid ForExtract and ReplicatDescriptionUse the GETTRUNCATESand IGNORE ...

  4. 31. Flatten Binary Tree to Linked List

    Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ex ...

  5. [转载]Macaca 测试 Android 应用:UIAutomator

    在用macaca进行自动化测试,想试一下移动端测试,看到这篇文章,尝试一下. 前言 用 Macaca 可以快速.便捷地进行安卓 native 的自动化测试,用简洁的 js 语法,写下用例,然后执行 M ...

  6. zk抢主

    package com.autonavi.tinfo.t1.traffic.pub.openlr.util; import java.util.Collections;import java.util ...

  7. jsp配置项目时出错Deployment failure on Tomcat 6.x. Could not copy all resources to

    转自:http://www.2cto.com/kf/201201/116853.html 今天在网上部署项目的时候出现在了问题 tomcat一直部署不上 网上查了一下 原因记下来供大家查看 Deplo ...

  8. COM的永久接口

    COM的永久接口

  9. 8.3 H5学习笔记

    隐藏域 <form action="" method="post" enctype="multipart/form-data"> ...

  10. UART UVM验证平台平台搭建总结

    tb_top是整个UVM验证平台的最顶层:tb_top中例化dut,提供时钟和复位信号,定义接口以及设置driver和monitor的virual interface,在intial中调用run_te ...