| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1691 人关注过本帖
标题:[讨论]]第十三期编程题目
只看楼主 加入收藏
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
 问题点数:0 回复次数:19 
[讨论]]第十三期编程题目

由于pcrazyc斑竹临时有事情.这期还是由我来出题目.希望大家继续支持.
第一题:

k尾相等数
Time Limit:1000MS Memory Limit:10000K
Description:
从键盘上输入一个整数k(k>1),若存在整数m,n(m>n),使得pow(k,m)和pow(k,n)均大于或等于1000,且末尾3位数相等,则称m和n是一对"k尾相等数"。请编写一程序求m+n值最小的k尾相等数。
input:
每行输入一个整数k;
output:
输出相应的最小m+n值;
sample input:
2
sample output
120


第二题:


Lagrange's Four-Square Theorem
Time Limit:1000MS Memory Limit:30000K
Total Submit:790 Accepted:339

Description
The fact that any positive integer has a representation as the sum of at most four positive squares (i.e. squares of positive integers) is known as Lagrange's Four-Square Theorem. The first published proof of the theorem was given by Joseph-Louis Lagrange in 1770. Your mission however is not to explain the original proof nor to discover a new proof but to show that the theorem holds for some specific numbers by counting how many such possible representations there are.
For a given positive integer n, you should report the number of all representations of n as the sum of at most four positive squares. The order of addition does not matter, e.g. you should consider 4^2 + 3^2 and 3^2 + 4^2 are the same representation.

For example, let's check the case of 25. This integer has just three representations 1^2+2^2+2^2+4^2, 3^2 + 4^2, and 5^2. Thus you should report 3 in this case. Be careful not to count 4^2 + 3^2 and 3^2 + 4^2 separately.


Input
The input is composed of at most 255 lines, each containing a single positive integer less than 2^15, followed by a line containing a single zero. The last line is not a part of the input data.

Output
The output should be composed of lines, each containing a single integer. No other characters should appear in the output.

The output integer corresponding to the input integer n is the number of all representations of n as the sum of at most four positive squares.

Sample Input

1
25
2003
211
20007
0

Sample Output

1
3
48
7
738

最后祝大家过一个愉快而又充实的五一!!!


简单翻译一下第二个:
就是把任意数字分解成不超过四个数字的平方和。{注意看紫色部分的例子说明}
问有多少种分法

[此贴子已经被作者于2007-4-27 17:08:31编辑过]

搜索更多相关主题的帖子: 题目 讨论 
2007-04-27 15:14
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
/*第二题的解答,不知道对不对?*/
#include <stdio.h>
int Lagrange(unsigned long n)
{ int way=0;
unsigned long a,b,c,d,a2,b2,c2,d2,s;
for(a=0,a2=a*a;a2<n;a++,a2=a*a)
for(b=a,b2=b*b;a2+b2<n;b++,b2=b*b)
for(c=b,c2=c*c;a2+b2+c2<n;c++,c2=c*c)
for(d=c,d2=d*d;(s=a2+b2+c2+d2)<=n;d++,d2=d*d)
if(s==n)way++;
return way;
}
main()
{
unsigned long n;
while(scanf("%lu",&n))
{
if(n==0)break;
printf("%d\n",Lagrange(n));
}
}
2007-04-27 17:38
Javal
Rank: 1
等 级:新手上路
威 望:1
帖 子:108
专家分:0
注 册:2006-5-7
收藏
得分:0 

写了下第一题,好像有些问题,请指正,thanks!
修改了一下,输入123454321也能获得正确结果

#include<stdio.h>
#include<math.h>
#define TRUE 1
#define FALSE 0

struct mantissa
{
int mant;
int exponent;
};

int main( void )
{
int k = 0;
int m = 0;
int n = 0;
int index = 0;
int i = 0;
int j = 0;
int flag = FALSE;
struct mantissa arr[1000];
for (i = 0; i < 1000; ++i)
{
arr[i].mant = 0;
}

printf("Please enter the value of k:\n");
scanf("%d", &k);

for (index = 0; pow(k, index) < 1000; ++index)
continue;

i = 0;
while(1)
{
if (i == 0)
{
arr[i].mant = (int)pow(k, index) % 1000;
}
else
{
/*----modified by javal, 09:07 28/04/2007----
arr[i].mant = (arr[i-1].mant * k) % 1000;
*-------------------------------------------*/
arr[i].mant = (arr[i-1].mant * (k % 1000) ) % 1000;

}
arr[i].exponent = index;
// printf("%d\t%d\n", arr[i].mant, arr[i].exponent);

for (j = 0; j < i; ++j)
{
if (arr[i].mant == arr[j].mant)
{
flag = TRUE;
m = arr[i].exponent;
n = arr[j].exponent;
break;
}
}
if (flag)
{
break;
}
i++;
index++;
}

printf("%d\n", m + n);

return 0;
}

[此贴子已经被作者于2007-4-28 9:13:55编辑过]


猝然临之而不惊,无故加之而不怒 /?spaced" target="_blank">Linux C资料
2007-04-27 18:04
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
/*第二题的解答,不知道对不对?*/
我给你提交了一下.超出时间了.
再改进一点点就能过.

[此贴子已经被作者于2007-4-27 18:10:47编辑过]


2007-04-27 18:05
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用Javal在2007-4-27 18:04:29的发言:

写了下第一题,好像有些问题,请指正,thanks!

#include<stdio.h>
#include<math.h>
#define TRUE 1
#define FALSE 0

struct mantissa
{
int mant;
int exponent;
};

int main( void )
{
int k = 0;
int m = 1;
int n = 0;
int index = 0;
int i = 0;
int j = 0;
int flag = FALSE;
struct mantissa arr[1000];
for (i = 0; i < 1000; ++i)
{
arr[i].mant = 0;
}

printf("Please enter the value of k:\n");
scanf("%d", &k);

for (index = 0; pow(k, index) < 1000; ++index)
continue;

i = 0;
while(1)
{
if (i == 0)
{
arr[i].mant = (int)pow(k, index) % 1000;
}
else
{
arr[i].mant = (arr[i-1].mant * k) % 1000;
}
arr[i].exponent = index;
// printf("%d\t%d\n", arr[i].mant, arr[i].exponent);

for (j = 0; j < i; ++j)//这里需要改进.
{
if (arr[i].mant == arr[j].mant)
{
flag = TRUE;
m = arr[i].exponent;
n = arr[j].exponent;
break;
}
}
if (flag)
{
break;
}
i++;
index++;
}

printf("%d\n", m + n);

return 0;
}

我看了一下思路基本上是对了.因为你求余数的方法很正确.估计错误不是很大.找找那写边界的地方
你还有这组数据不对:123454321  答案应该是27;


2007-04-27 18:23
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
这起题目比较简单.
大家加油.尤其是第二个只要多写点条件都能过.第二个大家自己
http://acm.pku.edu.cn/JudgeOnline/problem?id=2042提交.一定要注意输入输出不要输出没有用的东西.
第一个题目我给几个测试数据.要是都对的话就可以了:
输入      输出
25 7
125 6
1000 3
100000 102
123454321 27

2007-04-27 18:32
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
/*第一题的解答*/
#include <stdio.h>
main()
{
int m,n,k,a[10000],t;
printf("k=");
scanf("%d",&k);
for(t=m=1;m<10000;m++)
{
a[m]=t=t*k%1000;
for(n=1;n<m;n++)
if(t>=100 && t==a[n])goto suc;
}
suc:
//printf("tail=%d\n",t);
//printf("m=%d,n=%d\n",m,n);
printf("%d\n",m+n);
}
2007-04-27 18:39
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
以下是引用crackerwang在2007-4-27 18:32:56的发言:
这起题目比较简单.
大家加油.尤其是第二个只要多写点条件都能过.第二个大家自己
http://acm.pku.edu.cn/JudgeOnline/problem?id=2042提交.一定要注意输入输出不要输出没有用的东西.
第一个题目我给几个测试数据.要是都对的话就可以了:
输入      输出
25 7
125 6
1000 3
100000 102 这个数字太大
123454321 27 这个数字太大

each containing a single positive integer less than 2^15==32768

2007-04-27 18:42
yu_hua
Rank: 2
等 级:论坛游民
帖 子:222
专家分:95
注 册:2006-8-10
收藏
得分:0 
以下是引用crackerwang在2007-4-27 15:14:32的发言:

第一题:

k尾相等数
Time Limit:1000MS Memory Limit:10000K
Description:
从键盘上输入一个整数k(k>1),若存在整数m,n(m>n),使得pow(k,m)和pow(k,n)均大于或等于1000,且末尾3位数相等,则称m和n是一对"k尾相等数"。请编写一程序求m+n值最小的k尾相等数。
input:
每行输入一个整数k;
output:
输出相应的最小m+n值;
sample input:
2
sample output
120 好象不对!!!似应为114,具体地说m=107,n=7,末尾3位数均为128


2007-04-27 18:59
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
以下是引用yu_hua在2007-4-27 18:42:47的发言:

each containing a single positive integer less than 2^15==32768

这个是第二个题目的范围.
第一个题目的范围是long以内


2007-04-27 20:26
快速回复:[讨论]]第十三期编程题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012300 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved