Ignatius's puzzle
問題: 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 a,make the arbitrary integer x ,65|f(x)if
no exists that a,then print "no".
輸入:The input contains several test cases. Each test case consists of a nonegative integer k, More details in the Sample Input.
輸出:The output contains a string "no",if you can't find a,or you should output a line contains the a.More details in the Sample Output.
示例輸入: 11 100 9999
示例輸出: 22 no 43
問題分析:
5*x^13+13*x^5+k*a*x可以分成兩部分 即 5*x^13+13*x^5 和 k*a*x;
而第一個部分我們可以發現 (5*x^13+13*x^5)% 65 結果會不斷循環,循環節為65,而且為等差數列,差為18,則通過數學歸納法證明可得
隻要滿足(18 + k * x) % 65 == 0即可
代碼如下
# include <stdio.h>
int main()
{
int k, flag, x;
while(scanf("%d", &k) != EOF)
{
flag = 0;
for(x = 1; x <= 65; x++)
{
if ((18 + k * x) % 65 == 0)
{
flag = 1;
printf("%d\n", x);
break;
}
}
if (flag == 0)
{
printf("no\n");
}
}
return 0;
}