杭电oj1005 wrong answer(待改正)

#include<stdio.h>

int main(){
int c[51]={1,1};
int time;
int a,b,n;

int i;
while(scanf("%d %d %d",&a,&b,&n)!=EOF){
if(a==0&&b==0&&n==0)
break;
a%=7;
b%=7;
c[2]=(a*c[1]+b*c[0])%7;
c[3]=(a*c[2]+b*c[1])%7;
for(i=4;i<51;i++){
c[i]=(a*c[i-1]+b*c[i-2])%7;
if(c[i]==c[2]&&c[i+1]==c[3])
break;
}
time=i-2;
if(n>2)
printf("%d\n",c[(n-2)%time+1]);
else
printf("%d\n",c[n-1]);

}

return 0;
}

时间: 2024-10-19 12:34:16

杭电oj1005 wrong answer(待改正)的相关文章

杭电oj1005解题

1005AC+解题思路 分析: 1,题中(1 <= A, B <= 1000, 1 <= n <= 100,000,000),可知用蛮力肯定行不通. 2,  (A * f(n - 1) + B * f(n - 2)) mod 7 =(A%7*f(n-1)+B%7*f(n-2))%7 3,因f(i)和f(i+1) 只有49种组合,因为(f(i),(i+1)均只有7种选择,就是只能是0,1,2,3,4,5,6中的一个.故周期<=49. 解题: 1,先求周期,顺便把第一个周期的f(

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime

Song Jiang&#39;s rank list(杭电oj5131)(2014ACM/ICPC亚洲区广州站)

Song Jiang's rank list Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Total Submission(s): 168    Accepted Submission(s): 91 Problem Description <Shui Hu Zhuan>,also <Water Margin>was written by Shi Nai'a

杭电 KazaQ&#39;s Socks

KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbered from 1 to n in his closets. Every morning, he puts on a pair of socks which has the smallest number in the closets. Every evening, he puts this pair of socks in the basket

hdu1702(ACboy needs your help again!) 在杭电又遇坑了

点击打开链接 结题感悟: 其实吧,这题并不是很难,就是一个栈和队列的公共题,也就是按指定的方式(栈或队列)存取数据,但是为什么我自己写的栈和队列就是不能再杭电ac(一直wa啊),而用java包中的栈和队列就秒过了,问题尚未找出原因,值得思考啊.不过可以趁此学学这两个类(尽量还是自己动手写的好啊) 栈:java.util 类 Stack<E> Stack 类表示后进先出(LIFO)的对象堆栈.它通过五个操作对类 Vector 进行了扩展 ,允许将向量视为堆栈.它提供了通常的push 和 pop

杭电 1272 POJ 1308 小希的迷宫

这道题是我学了并查集过后做的第三个题,教我们的学姐说这是并查集的基础题,所以有必要牢牢掌握. 下面就我做这道题的经验,给大家一些建议吧!当然,我的建议不是最好的,还请各位大神指出我的错误来,我也好改正. 1.题目概览 这道题是杭电1272,POJ 1308如果写好了代码可以试一试. 小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s

杭电 3555 Bomb

Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 6609    Accepted Submission(s): 2303 Problem Description The counter-terrorists found a time bomb in the dust. But this time the terrorists

acm入门 杭电1001题 有关溢出的考虑

最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n. Input The input will consist of a series of integers n, one integer per line Output For each case, output SUM(n) in one line

杭电 HDU ACM 5186 zhx&#39;s submissions

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1892    Accepted Submission(s): 507 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many