数论 : 模运算法则(poj 1152)
题意:求给出数的最小进制。
思路:暴力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 >= '' && x <= '')
return x - '';
else if(x >= 'A' && x <= 'Z')
return x - 'A' +;
else if(x >= 'a' && x <= 'z')
return x - 'a' +;
return ;
}
string s;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(cin>>s){
int n = s.size();
int maxn = ,sum = ;
for(int i = ;i < n;i++){
sum +=cal(s[i]);
maxn = max(maxn, cal(s[i]));
}
int flag = ;
for(int i = maxn+; i <= ; i++)
if(sum%(i-) == ){
printf("%d\n",i);
flag = ;
break;
}
if(flag)
printf("such number is impossible!\n");
}
return ;
}
数论 : 模运算法则(poj 1152)的更多相关文章
- #数论-模运算#POJ 1150、1284、2115
1.POJ 1150 The Last Non-zero Digit #质因数分解+模运算分治# 先贴两份题解: http://www.hankcs.com/program/algorithm/poj ...
- 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 ...
- POJ 1152 An Easy Problem! (取模运算性质)
题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...
- poj 3980 取模运算
取模运算 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10931 Accepted: 6618 Description ...
- java 取模运算% 实则取余 简述 例子 应用在数据库分库分表
java 取模运算% 实则取余 简述 例子 应用在数据库分库分表 取模运算 求模运算与求余运算不同.“模”是“Mod”的音译,模运算多应用于程序编写中. Mod的含义为求余.模运算在数论和程序设计中 ...
- a ^ b mod c 取模运算优化反思(老物)
这是一篇嘲讽我之前的自己采用笨重愚蠢思想去解决问题的日志. RSA 加密与解密涉及到 a ^ b mod c 的问题,如何计算这个值呢? 我会选择 pow(a, b) % c, 事实上在写RSA的时候 ...
- mysql中的优化, 简单的说了一下垂直分表, 水平分表(有几种模运算),读写分离.
一.mysql中的优化 where语句的优化 1.尽量避免在 where 子句中对字段进行表达式操作select id from uinfo_jifen where jifen/60 > 100 ...
- c++ 模运算
在数学里,"模运算"也叫"求余运算",用mod来表示模运算. 对于 a mod b 可以表示为 a = q(商)*b(模数) + r(余数),其中q表示商,b表 ...
- 二分求幂/快速幂取模运算——root(N,k)
二分求幂 int getMi(int a,int b) { ; ) { //当二进制位k位为1时,需要累乘a的2^k次方,然后用ans保存 == ) { ans *= a; } a *= a; b / ...
随机推荐
- 谈谈Java利用原始HttpURLConnection发送POST数据
这篇文章主要给大家介绍java利用原始httpUrlConnection发送post数据,设计到httpUrlConnection类的相关知识,感兴趣的朋友跟着小编一起学习吧 URLConnectio ...
- C# 时间类型
字符型转换为字符串// C 货币 2.5.ToString("C"); // ¥2.50 // D 10进制数 25.ToString("D5"); // 25 ...
- Java正则表达式详解
转自http://edu.yesky.com/edupxpt/18/2143018.shtml
- C++ 如何有效地使用对话框
Q:如何在对话框中加入工具条 在 OnInitDialog 中加入下面代码: BOOL CYourDlg::OnInitDialog() { CDialog::OnInitDialog(); // C ...
- 剑指Offer:面试题28——字符串的排列(java实现)(待序)
问题描述: 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 结果请按字母 ...
- 北京市小升初 zz
发信人: django (牛魔王), 信区: SchoolEstate 标 题: 北京市小升初掐尖方式的演变过程(看后恍然大悟) 发信站: 水木社区 (Thu Feb 4 10:51:23 201 ...
- Home not found. Define system property "openfireHome" or create and add the openfire_init.xml file to the classpath
启动openfire后出现这个错误,貌似什么配置没对吧.网上搜索了下,找到解决办法, $ vi /etc/profile在里面加入:export openfireHome=/opt/openfire ...
- vc6 编译问题
Compiling...main.cppLinking...MSVCRT.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in LIB ...
- 【EF学习笔记05】----------操作内存中的数据
SingleOrDefault实验 //SingleOrDefault实验 using (var db = new Entities()) { var classes = new Classes() ...
- 第五百八十二天 how can I 坚持
好吧,是我错了,昨天,做好自己就行了,别人怎么样是别人的事,永远保持一颗单纯向上的心. 时间过得真快,明天又周六了.. 睡觉.