数论 : 模运算法则(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 / ...
随机推荐
- Chap6: question 46 - 48
46. 求 1+2+ … +n. 要求:不用乘除法.for.while.if.else.switch.case 以及条件判断语句(A?B:C). a. 利用构造函数求解 #include <io ...
- 简单实用的Windows命令(一)
前几天新买了一台笔记本电脑,使用了一下几个简单的查看电脑配置的命令,觉得非常的不错,在此记录一下 一:运行命令的方式有两种 1:使用快捷键WIN+R,然后在弹出的“运行”对话框中输入对应的命令 2:在 ...
- C# 指定物理目录下载文件,Response.End导致“正在中止线程”异常的问题
FileHandler http://www.cnblogs.com/vipsoft/p/3627709.html UpdatePanel无法导出下载文件: http://www.cnblogs.co ...
- Loadrunner:LR提交JSON格式的POST请求
场景: 影视分发:影院客户端向管理平台发起取任务的操作,取任务接口getDispatchTask,为JSON格式的POST请求 Action() { web_custom_request(" ...
- leetcode 160
160. Intersection of Two Linked Lists Write a program to find the node at which the intersection of ...
- 初识Memcached
一,什么是memcached? Memcached是一个高性能的分布式内存对象缓存系统,用于动态web应用以减轻数据库负载..它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱 ...
- linq to entity中遇到的问题
当使用 from m in _db.students从数据库中获取数据时,数据库中的数据类型和C#中的不同,所以可能会出错!先作_db.students.ToList()然后select
- Web前端之CSS_day3-4
1.行高 1.1 初始行高 行高=文字大小+上间距+下间距 默认文字大小:16px 默认文字行高:18px 注意:行高=盒子的高度,可以让文字垂直居中显示 1.2 行高单位 a. px 行高设置多少就 ...
- Python延迟打印字符
我想让python打印类似“正在加载...”,每个句号打印出来与它们之间的睡眠时间0.5秒间隔 实现方法: 1 2 3 4 5 6 7 8 9 10 11 #!/bin/env python # -* ...
- 安卓中adapter的应用
个人菜鸟总结,期待大神指点,悉心倾看! Adapter是ListView界面与数据之间的桥梁,Adapter提供对数据的访问,也负责为每一项数据产生一个对应的View(白话通俗点:先写adapter为 ...