Hdu 1098 Ignatius's puzzle

By | 03月25日
Advertisement

1、一开始读题,65|f(x)是什么意思都不清楚,最后百度才知道是f(x)能被65整除。

2、而且写这题完全没有思路,数论不好,我是根据网上的思路写的。

思路:
则f(x+1 ) = f (x) + 5*( (13 1 ) x^12 ...... .....+(13 13) x^0 )+ 13*( (5 1 )x^4+...........+ ( 5 5 )x^0 )+k*a;

很容易证明,除了5*(13 13) x^0 、13*( 5 5 )x^0 和k*a三项以外,其余各项都能被65整除.
那么也只要求出18+k*a能被65整除就可以了.
而f(1)也正好等于18+k*a:题目的关键是函数式f(x)=5*x^13+13*x^5+k*a*x;
事实上,由于x取任何值都需要能被65整除.那么用数学归纳法.只需找到f(1)成立的a,并在假设f(x)成立的基础上,
证明f(x+1)也成立.
那么把f(x+1)展开,得到5*( ( 13 0 )x^13 + (13 1 ) x^12 ...... .....+(13 13) x^0)+13*( ( 5 0 )x^5+(5 1 )x^4......其实就是二项式展开,这里就省略了 ......+ ( 5 5 )x^0 )+k*a*x+k*a;——————这里的( n m)表示组合数,相信学过2项式定理的朋友都能看明白.

然后提取出5*x^13+13*x^5+k*a*x。

则f(x+1 ) = f (x) + 5*( (13 1 ) x^12 ...... .....+(13 13) x^0 )+ 13*( (5 1 )x^4+...........+ ( 5 5 )x^0 )+k*a;

很容易证明,除了5*(13 13) x^0 、13*( 5 5 )x^0 和k*a三项以外,其余各项都能被65整除.
那么也只要求出18+k*a能被65整除就可以了.
而f(1)也正好等于18+k*a

所以,只要找到a,使得18+k*a能被65整除,也就解决了这个题目.

假设存在这个数a,因为对于任意x方程都成立,所以,当x=1时f(x)=18+ka;有因为f(x)能被65整出,这可得出f(x)=n*65;

即:18+ka=n*65;若该方程有整数解则说明假设成立。

ax+by = c的方程有解的一个充要条件是:c%gcd(a, b) == 0。

然后枚举直到65*n-18%k == 0为止。

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int gcd(int a, int b)
{
return b == 0? a:gcd(b, a%b);
}

void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}

int fun(int m, int n)
{
if(m < n) swap(m, n);
gcd(m, n);
if(!(18%gcd(m, n))) return 1;
return 0;
}

int main()
{
int m;
while(~scanf("%d", &m))
{
if(fun(65, m))
{
for(int i = 1;; i++)
{
if((i*65-18)%m == 0)
{
printf("%dn", (i*65-18)/m);
break;
}
}
}
else printf("non");
}
return 0;

}

思路2:

题意:给出k。求使得f(x)=5*x^13+13*x^5+k*a*x对任意x都为65的倍数的a的最小值。

mark:65=13*5。要使f(x)是65的倍数,只需要f(x)是5和13的倍数即可。先来分析13的。

若f(x)是13的倍数,

有5*x^13+13*x^5+k*a*x % 13 == 0,其中13*x^5项显然不用考虑。

则只需5*x^13 + k*a*x是13的倍数,即x*(5*x^12+k*a)是13的倍数。若x是13的倍数,不用考虑。

若x不是13的倍数,则x一定与13互素,因为EulerPhi(13) == 12,从而x^12 % 13 == 1。

所以可知5*x^12 % 13 == 5。

因为要让任意x满足条件,则括号内必为13的倍数,有k*a+5 % 13 == 0,则k*a % 13 == 8。

同理可得k*a % 5 == 2。

据此,若k为5或13的倍数,a一定无解,否则,一定有解。

根据k%5的结果,可能为1、2、3、4,a应分别取5n+2,5n+1,5n+4,5n+3。

枚举a的值,若符合13的条件,则为解。

费马小定理:

费马小定理是数论中的一个重要定理,其内容为: 假如p是质数,且(a,p)=1,那么 a^(p-1) ≡1(mod p) 假如p是质数,且a,p互质,那么 a的(p-1)次方除以p的余数恒等于1 。

CODE:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int tab5[5]={0, 2, 1, 4, 3};

int main()
{
int k;
while(~scanf("%d", &k))
{
if(k % 5 == 0 || k % 13 == 0)
{
printf("non");
continue;
}
for(int a = tab5[k%5]; ; a+=5)
{
if(k*a%13 == 8)
{
printf("%dn", a);
break;
}
}
}
return 0;

}

Similar Posts:

  • HDU 1098 Ignatius&#39;s puzzle(数论-其它)

    Ignatius's puzzle Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal

  • HDU 1098 Ignatius&#39;s puzzle

    Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8526 Accepted Submission(s): 5907 Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choic

  • HDU 1098 Ignatius&#39;s puzzle 【数学(特殊值总结) Or 规律(瞎搞)】

    Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal nonegative integer

  • 杭电acm1098 Ignatius&amp;amp;#39;s puzzle

    杭电acm1098 Ignatius's puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3894 Accepted Submission(s): 2608 Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he ha

  • HDOJ 1098 Ignatius&#39;s puzzle

    Problem Description Ignatius is poor at math,he falls across a puzzle problem,so he has no choice but to appeal to Eddy. this problem describes that:f(x)=5*x^13+13*x^5+k*a*x,input a nonegative integer k(k<10000),to find the minimal nonegative integer

  • HDU 1028 Ignatius and the Princess III(母函数)

    题目:HDU-1028 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028 题目: Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16806 Accepted Submission(s): 11830 Problem Descri

  • 【搜索之BFS + 优先队列】杭电 hdu 1026 Ignatius and the Princess I

    /* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : http://acm.hdu.edu.cn/showproblem.php?pid=1026 Name : 1026 Ignatius and the Pri

  • Hdu 1163 Eddy&amp;amp;#39;s digital Roots + NYOJ-485 A*B Problem(九余数定理)

    参考自:Hdu-1163 Eddy's digital Roots(九余数定理) - 飘过的小牛 - 博客频道 - CSDN.NET 九余数定理:一个数的每位数字之和等于这个数对9取余,如果等于0就是9 Hdu 1163 Eddy's digital Roots 题意:给定一个正整数,根据一定的规则求出该数的"数根",其规则如下: 例如给定 数字 24,将24的各个位上的数字"分离",分别得到数字 2 和 4,而2+4=6: 因为 6 < 10,所以就认为6是

  • HDU 1027 Ignatius and the Princess II [康托逆展开]【数学】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027 --------------–. Ignatius and the Princess II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7182 Accepted Submission(s): 4264 Problem Descript

  • HDU 3105 Fred&amp;amp;#39;s Lotto Tickets(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3105 Problem Description Fred likes to play the lotto. Whenever he does, he buys lots of tickets. Each ticket has 6 unique numbers in the range from 1 to 49, inclusive. Fred likes to ``Cover all his base

Tags: