ZOJ 1489 2^x mod n = 1 数论】的更多相关文章

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=489 题目大意: 给你正整数n,求最小的x使得2^x mod n = 1. 思路: n=1无解.任何正数mod 1都为0吧 n为偶数无解,why? 上式可变形为: 2^x=k*n+1,若n为偶数那么k*n+1为奇数,而2^x必为偶数. n为奇数一定有解,对于乘法逆元:在a mod n的操作下,a存在乘法逆元当且仅当a与n互质. #include<cstdio> int mai…
2^x mod n = 1 Time Limit: 2 Seconds      Memory Limit:65536 KB Give a number n, find the minimum x that satisfies 2^x mod n = 1. Input One positive integer on each line, the value of n. Output If the minimum x exists, print a line with 2^x mod n = 1.…
Remainder Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3036    Accepted Submission(s): 679 Problem Description Coco is a clever boy, who is good at mathematics. However, he is puzzled by a d…
Factorial Problem in Base K Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3621 Description How many zeros are there in the end of s! if both s and s! are written in base k which is not nece…
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY…
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  1027   Human Gene Functions   简单题  1037   Gridland            简单题  1052   Algernon s Noxious Emissions 简单题  1409   Commun…
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116…
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive…
题目大意:输入一个整数n,输出使2^x mod n = 1成立的最小值K 解题思路:简单数论 1)n可能不能为偶数.因为偶数可不可能模上偶数以后==1. 2)n肯定不可能为1 .因为任何数模上1 == 0: 3)所以n肯定是除1外的奇数 代码如下: #include <iostream> using namespace std; int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n == 1 || n % 2 ==…
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1123.html 题目传送门 - 51Nod1123 题意 $T$ 组数据. 给定 $A,B,C$,求出使得 $x^A \equiv C \pmod B$ 的所有 $x$,保证解的个数不超过 $\sqrt B$ . $T\leq 100,1\leq A,B,C \leq 10^9$ 题解 先记一下写这一题的感受: 1. 写的过程中代码长度峰值达到过 300 行,好久没写码农题了,感到自己码力大减.…
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2480.html 题目传送门 - BZOJ2480 题意 已知数 $a,p,b$ ,求满足 $a^x≡b \pmod p $ 的最小自然数 $x$ . $a,p,b\leq 10^9$ 题解 ExBSGS模板题. UPD(2018-09-10): 详见数论总结. 传送门 - https://www.cnblogs.com/zhouzhendong/p/Number-theory-Residue-Sys…
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1039.html 题目传送门 - 51Nod1039 题意 题解 这题我用求高次剩余的做法,要卡常数. UPD(2018-09-10): 详见数论总结. 传送门 - https://www.cnblogs.com/zhouzhendong/p/Number-theory-Residue-System.html 代码 #include <bits/stdc++.h> using namespace…
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1038.html 题目传送门 - 51Nod1038 题意 题解 在模质数意义下,求高次剩余,模板题. UPD(2018-09-10): 详见数论总结. 传送门 - https://www.cnblogs.com/zhouzhendong/p/Number-theory-Residue-System.html 代码 优化了一下代码……原来的那个在这一份后面…… #include <bits/stdc…
Power of Fibonacci Time Limit: 5 Seconds      Memory Limit: 65536 KB In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, .…
题目大意: 求出一个最小的x 使得 2的x次方对n取模为1 思路分析: 若要 a*b%p=1  要使得b存在 则 gcd (a,p)=1. 那么我们应用到这个题目上来. 当n为偶数 2^x 也是偶数,那么gcd 肯定不是1.故这个是不存在的. 那么n为奇数的时候,也就一定是1了. 所以直接暴力找. #include <iostream> #include <cstdio> using namespace std; int main() { int n; while(scanf(&q…
Problem 1752 A^B mod C Accept: 579    Submit: 2598Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,B,C<2^63). Input There are multiply testcases. Each testc…
思路:容易得到s[n]=s[n-1]+s[n-2],也就是fib数. 求第k小的fib质数的也就是第k个质数数-2,当k>2时. 在就是s[n]/x%m=s[n]%(x*m)/x. 代码如下: #include<cstdio> #include<algorithm> #include<cstring> #define ll long long #define M 1000005 using namespace std; ll k,x,m; int prime[M]…
Description Kitty is a little cat. She is crazy about a game recently. There arenscenes in the game(mark from 1 ton). Each scene has a numberpi. Kitty's score will become least_common_multiple(x,pi) when Kitty enter theithscene.xis the score that Kit…
So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5905    Accepted Submission(s): 1966 Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei…
The Children's Day has passed for some days .Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends. Now I introduce the game to you. Suppose there are N people played the…
What day is that day? Time Limit: 2 Seconds Memory Limit: 65536 KB It's Saturday today, what day is it after 11+22+33+...+NN1^1 + 2^2 + 3^3 + ... + N^N11+22+33+...+NN days? Input There are multiple test cases. The first line of input contains an inte…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5176 AX+BY = XY  => (X-B)*(Y-A)= A*B 对A*B因式分解,这里不要乘起来,分A,B因式分解 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> #inc…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4888 标题两个参数,途径:小参数的枚举,然后二分法大参数 想想两个点.以后就不会了两个参数  然后在暴力,实上K能够非常大 所以时间不够 自己写的二分枚举+高速幂程序WA了非常久. .. .没明确哪里错了  參考了别人的... //#pragma comment(linker, "/STACK:102400000,102400000") #include <c…
What day is that day? Time Limit: 2 Seconds      Memory Limit: 65536 KB It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are multiple test cases. The first line of input contains an integer T indicating the number o…
本题涉及博弈论中的Nim游戏博弈. Nim游戏博弈详解链接: http://www.cnblogs.com/exponent/articles/2141477.html 本题解题报告详解链接: http://blog.csdn.net/woshi250hua/article/details/7824609 我的代码,写的较挫,4000多ms,压着时间过,时间限制是5s.我预处理了所有1-5*10^6的数的素因子个数,用的是dp 的思想,先预处理1-5*10^6的数的最小素因子,存在a数组中,然后…
Challenge of Wisdom Time Limit: 2 Seconds      Memory Limit: 32768 KB Background "Then, I want to know whether you're a wise boy!" Problem "I have a great deal of lands. They're divided into N*M grids (N, M <= 1,000,000,000). When you ar…
\[设c=gcd(a,b),那么a可以表示为mc,b可以表示为nc的形式.然后令a=kb+r,那么我们就\\ 只需要证明gcd(b,r)=c即可.{\because}r=a-kb=mc-knc,{\therefore}gcd(b,r)=gcd(nc,mc-knc)\\ =gcd(nc,(m-kn)c),所以我们只需要证gcd(n,m-kn)=1即可.\\ 设n=xd,m-kn=yd,那么m=kn+yd=kxd+yd,进而a=(kx+y)cd,b=xcd\\ ,于是gcd(a,b)就可以表示为gc…
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889 1904 1915 1949 2001 2022 2099 2104 21…
又是数论题 Q&A Q:你TM做数论上瘾了吗 A:没办法我数论太差了,得多练(shui)啊 题意 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入输出格式 输入格式: 输入文件名为equation .in. 输入共n + 2 行. 第一行包含2 个整数n .m ,每两个整数之间用一个空格隔开. 接下来的n+1 行每行包含一个整数,依次为a0,a1,a2..an 输出格式: 输出文件名为equation…
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; typedef long long int64; ]; int64 A,B,K,pi,pk,ans,ti,q; int64 ksm(int64 x,int64 y){ ) ; ) return x; int64 d=k…