题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110042#overview 密码:nefu
一些题目相对简单了些:
A题POJ2478: http://poj.org/problem?id=2478
题面描述:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 14329 | Accepted: 5668 |
Description
F2 = {1/2}
F3 = {1/3, 1/2, 2/3}
F4 = {1/4, 1/3, 1/2, 2/3, 3/4}
F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5}
You task is to calculate the number of terms in the Farey sequence Fn.
Input
Output
Sample Input
2 3 4 5 0
Sample Output
1 3 5 9
代码实现:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int euler[1000010];
void getEuler()
{
memset(euler,0,sizeof(euler));
euler[1]=1;
for(int i=2;i<=1000000;i++)
{
if(!euler[i])
for(int j=i;j<=1000000;j+=i)
{
if(!euler[j])
euler[j]=j;
euler[j]=euler[j]/i*(i-1);
}
}
}
long long f[1000010];
void fi()
{
memset(f,0,sizeof(f));
for(int i=2;i<=1000000;i++)
{
f[i]=f[i-1]+euler[i];
}
}
int main()
{
int n;
getEuler();
fi();
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
printf("%lld\n",f[n]);
}
return 0;
}
B题:POJ 1006 http://poj.org/problem?id=1006
题面描述:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 125974 | Accepted: 39821 |
Description
Since the three cycles have different periods, the peaks of the three cycles generally occur at different times. We would like to determine when a triple peak occurs (the peaks of all three cycles occur in the same day) for any person. For each cycle, you will be given the number of days from the beginning of the current year at which one of its peaks (not necessarily the first) occurs. You will also be given a date expressed as the number of days from the beginning of the current year. You task is to determine the number of days from the given date to the next triple peak. The given date is not counted. For example, if the given date is 10 and the next triple peak occurs on day 12, the answer is 2, not 3. If a triple peak occurs on the given date, you should give the number of days to the next occurrence of a triple peak.
Input
Output
Case 1: the next triple peak occurs in 1234 days.
Use the plural form ``days'' even if the answer is 1.
Sample Input
0 0 0 0 0 0 0 100 5 20 34 325 4 5 6 7 283 102 23 320 203 301 203 40 -1 -1 -1 -1
Sample Output
Case 1: the next triple peak occurs in 21252 days. Case 2: the next triple peak occurs in 21152 days. Case 3: the next triple peak occurs in 19575 days. Case 4: the next triple peak occurs in 16994 days. Case 5: the next triple peak occurs in 8910 days. Case 6: the next triple peak occurs in 10789 days.
代码实现:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int M=29;
int main()
{
int p,e,i,d;
int sum;
int casenum=0;
while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF)
{
if(p==-1&&e==-1&&i==-1&&d==-1)
break;
sum=(5544*p+14421*e+1288*i-d+21252)%21252;
if(sum==0)
sum=21252;
printf("Case %d: the next triple peak occurs in %d days.\n",++casenum,sum);
}
return 0;
}
C题:codeforces 7C : http://www.codeforces.com/problemset/problem/7/C
题面描述:
A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.
If the required point exists, output its coordinates, otherwise output -1.
2 5 3
6 -3
代码实现:
#include <stdio.h>
#include <iostream>
using namespace std;
long long gcd(long long a,long long b)
{
if(b==0)
return a;
else return gcd(b,a%b);
}
void ex_gcd(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
return;
}
ex_gcd(b,a%b,y,x);
y-=a/b*x;
return;
}
int main()
{
long long a,b,c;
long long x0,y0;
while(scanf("%lld%lld%lld",&a,&b,&c)!=EOF)
{
c=-c;
if(a==0&&b!=0)
{
if(c%b==0)
{
printf("0 %lld\n",c/b);
}
else printf("-1\n");
}
if(a!=0&&b==0)
{
if(c%a==0)
{
printf("%lld 0\n",c/a);
}
else printf("-1\n");
}
if(a!=0&&b!=0)
{
if(c==0)
{
printf("0 0\n");
}
else
{
long long d=gcd(a,b);
if(c%d!=0)
{
printf("-1\n");
}
else
{
a=a/d;
b=b/d;
c=c/d;
ex_gcd(a,b,x0,y0);
x0=x0*c;
x0=((x0%b)+b)%b;
y0=(c-a*x0)/b;
printf("%lld %lld\n",x0,y0);
}
}
}
}
return 0;
}
D题:HDU2588 : http://acm.hdu.edu.cn/showproblem.php?pid=2588
题面描述:
GCD
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1442 Accepted Submission(s): 676
(a,b) can be easily found by the Euclidean algorithm. Now Carp is considering a little more difficult problem:
Given integers N and M, how many integer X satisfies 1<=X<=N and (X,N)>=M.
3 1 1 10 2 10000 72
1 6 260
代码实现:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int euler;
long long getEuler(long long n)
{
long long ans=n;
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
ans-=ans/i;
while(n%i==0)
n/=i;
}
}
if(n>1)
ans-=ans/n;
return ans;
}
int main()
{
int T;
int n,m;
int sum;
scanf("%d",&T);
while(T--)
{
sum=0;
scanf("%d%d",&n,&m);
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
if(i>=m)
{
sum+=getEuler(n/i);
}
if((n/i)!=i&&(n/i)>=m)
{
sum+=getEuler(i);
}
}
}
printf("%d\n",sum);
}
return 0;
}