摘要: 题意: 判断一个关于n的多项式P(n)能否恒被一个正整数D整除。 输入样例: (n^2-n)/2 (2n^3+3n^2+n)/6 (-n^14-11n+1)/3 输出格式: 如果满足条件就输出“Always an integer”否则输出“Not always an integer”。 分析: 多项 阅读全文
posted @ 2016-08-25 14:38 Yan_Bin 阅读(195) 评论(0) 推荐(0)
摘要: Investigating Div-Sum Property Aninteger is divisible by 3 if the sum of its digits is also divisible by 3. Forexample, 3702 is divisible by 3 and 12( 阅读全文
posted @ 2016-08-25 11:25 Yan_Bin 阅读(191) 评论(0) 推荐(0)
摘要: 也可以由欧拉定理,对任意a属于Zn,a^(phi(n))=1(modn)。于是a的逆就是a^(phi(n) - 1)。 如果n是素数的话,a的逆就是pow_mod(a,n-2,n) 阅读全文
posted @ 2016-08-25 00:53 Yan_Bin 阅读(156) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 // 计算欧拉phi函数。phi(n)是不超过n且与n互素的正整数个数 5 int euler_phi(int n){ 6 int m = (int)sqrt(n + 0.5); 7 int ans = n; 8 // phi(n)=n(1-1/p1)(1-1/p2)...(1-1... 阅读全文
posted @ 2016-08-25 00:36 Yan_Bin 阅读(713) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 LL pow_mod(LL a,LL p,LL n){ 7 if(p == 0) return 1; 8 LL ans = pow_mod(a,p / 2,n); 9 ans = ans... 阅读全文
posted @ 2016-08-24 23:56 Yan_Bin 阅读(109) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 // 求x和y使得ax+by=d并且|x|+|y|最小。其中d=gcd(a,b) 7 void exgcd(LL a,LL b,LL& d,LL& x,LL& y){ 8 if(!b) d = a,x =... 阅读全文
posted @ 2016-08-24 23:50 Yan_Bin 阅读(111) 评论(0) 推荐(0)
摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 const int maxn = 10000000; 6 const int maxp = 700000; 7 const int MOD = 1e9; 8 typedef long long LL; 9 int vis[maxn]; //vis[i] =... 阅读全文
posted @ 2016-08-24 23:43 Yan_Bin 阅读(154) 评论(0) 推荐(0)
摘要: Exploring Pyramids Archaeologists have discovered a new set of hidden caves in one of the Egyptian pyramids. The decryption of ancient hieroglyphs on 阅读全文
posted @ 2016-08-24 23:02 Yan_Bin 阅读(142) 评论(0) 推荐(0)
摘要: 带标号连通图计数。统计有n(n<=50)个顶点的连通图有多少个。图的顶点有编号。例如n=3时有4个不同的图,n=4时有38个图,n=5时有728个图,n=6时有26704个图。 分析:设f(n)为所求答案,g(n)为有n个顶点的非连通图,则f(n)+g(n)=h(n)=2^n*(n-1)/2。g(n 阅读全文
posted @ 2016-08-24 19:44 Yan_Bin 阅读(958) 评论(0) 推荐(0)
摘要: Ingenuous Cubrency People in Cubeland use cubic coins. Not only the unit of currency is called acube but also the coins are shaped like cubes and thei 阅读全文
posted @ 2016-08-24 18:46 Yan_Bin 阅读(243) 评论(0) 推荐(0)