Problem A:八目鳗烧烤店 Time Limit:1000MS Memory Limit:65536K Description 八目鳗烧烤店一共有6个八目鳗,幽幽子一口能吃1到6个八目鳗,求吃完所有的八目鳗共有多少种吃法。 Input 无 Output 输出一个整数,表示吃完所有的八目鳗共有多少种吃法。 Sample Input
Sample Output
Hint #include |
编程思想:简单递推。
AC code:
#include <stdio.h>
#include <math.h>
#include<string.h>
int f[6];
int main()
{
int i,j;
memset(f,0,sizeof(f));
f[1]=1;
f[2]=2;
for(i=3;i<=6;i++)
{
for(j=1;j<i;j++)
f[i]+=f[j];
f[i]++;
}
printf("%d\n",f[6]);
return 0;
}
roblem B:琪露诺的完美算术教室(三)(Easy)
Time Limit:1000MS Memory Limit:65536K
Total Submit:140 Accepted:26
Description
去年琪露诺又没把结果算出来,这一年里又被当成笨蛋了,但是琪露诺还是不服!为了洗刷被当成笨蛋的耻辱,于是这次她要挑战计算的是A^B mod C(A的B次方对C取余)
Input
输入数据第一行有三个整数A、B、C( 1 <= A,B,C < 10000)。
Output
输出A^B mod C的结果。
Sample Input
3 2 4
Sample Output
1
编程思想:快速幂的应用。
AC code:
#include <stdio.h>
#include <math.h>
#include<string.h>
#define LL long long
int gcd(int a,int b)
{
if(a<b)
{
int t=a;
a=b;
b=t;
}
if(b==0) return a;
else return gcd(b,a%b);
}
LL PowerMod(LL a,LL b,LL c)
{
LL ans=1;
a=a%c;
while(b>0)
{
if(b&1) ans=(ans*a)%c;
b>>=1;
a=(a*a)%c;
}
return ans;
}
int main()
{
LL a,b,c;
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
printf("%I64d\n",PowerMod(a,b,c));
}
return 0;
}
Problem C:琪露诺的完美算术教室(三)(Hard) Time Limit:1000MS Memory Limit:65536K Description Input 输入数据第一行有三个整数A、B、C(1<=A,C<10000,1<=B<=10^18)。 Output 输出A^B mod C的结果。 Sample Input
3 2 4 Sample Output
1 Hint 用long long代替int可以存储10^18的整数 |
编程思想:快速幂。
AC code:
#include <stdio.h>
#include <math.h>
#include<string.h>
#define LL long long
int gcd(int a,int b)
{
if(a<b)
{
int t=a;
a=b;
b=t;
}
if(b==0) return a;
else return gcd(b,a%b);
}
LL PowerMod(LL a,LL b,LL c)
{
LL ans=1;
a=a%c;
while(b>0)
{
if(b&1) ans=(ans*a)%c;
b>>=1;
a=(a*a)%c;
}
return ans;
}
int main()
{
LL a,b,c;
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
printf("%I64d\n",PowerMod(a,b,c));
}
return 0;
}