分拆素数和
把一个偶数拆成两个不同素数的和,有几种拆法呢?
Input
输入包含一些正的偶数,其值不会超过10000,个数不会超过500,若遇0,则结束。
Output
对应每个偶数,输出其拆成不同素数的个数,每个结果占一行。
Sample Input
30260
Sample Output
32
#include<stdio.h>
#include<math.h>
int fun(int m)
{
int i,k=1;
for(i=2;i<=sqrt(m);i++)
{
if(m%i==0)
k=0;
}
return k;
}
int main()
{
int m,i,k=0;
while(scanf("%d",&m)!=EOF)
{
if(m==0)
break;
for(i=2;i<=m;i++)
{
if(fun(i)==1&&fun(m-i)==1)
k++;
}
if(fun(m/2)!=1)
printf("%d\n",k/2);
else
printf("%d\n",(k+1)/2);
k=0;
}
}
结果是Time Limit Exceeded
2.
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybody objects to this BT problem,so lcy makes the problem easier than begin.this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output
For each test case, you should output the a^b's last digit number.
Sample Input
7 668 800
Sample Output
96
我的
#include<stdio.h>
int main()
{
int a,b,i;
int T=1;
while(scanf("%d%d",&a,&b)!=EOF)
{
for(i=1;i<=b;i++)
{
T=T*a;
T=T%10;
}
printf("%d\n",T);
T=1;
}
}
还是超时
求大神帮我修改!!!
初学c语言
ç»ä½ ä¸æè·¯å§
第ä¸ä¸ª ç´ æ°ç®æ³ä¸å¥½ æ¹ç¨ç´ æ°ç 没å¬è¯´è¿çè¯ èªå·±æ å¾å¸¸ç¨çç®æ³
第äºä¸ª 对äºaå æ±ä¸ªä½æ° ç¶åæç §ä½ çç®æ³æ±å¼
å¦æè¿æ¯è¶ æ¶çè¯
é£ä¹è¿è¡æåéå½
类似äº
int get_value(int a, int b)