博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1.4.1 Arithmetic Progressions
阅读量:5149 次
发布时间:2019-06-13

本文共 1936 字,大约阅读时间需要 6 分钟。

An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb where n=0,1,2,3,... . For this problem, a is a non-negative integer and b is a positive integer.

Write a program that finds all arithmetic progressions of length n in the set S of bisquares. The set of bisquares is defined as the set of all integers of the form p2 + q2 (where p and q are non-negative integers).

TIME LIMIT: 5 secs

PROGRAM NAME: ariprog

INPUT FORMAT

Line 1:

N (3 <= N <= 25), the length of progressions for which to search

Line 2:

M (1 <= M <= 250), an upper bound to limit the search to the bisquares with 0 <= p,q <= M.

SAMPLE INPUT (file ariprog.in)

5

7

OUTPUT FORMAT

If no sequence is found, a single line reading `NONE'. Otherwise, output one or more lines, each with two integers: the first element in a found sequence and the difference between consecutive elements in the same sequence. The lines should be ordered with smallest-difference sequences first and smallest starting number within those sequences first.

There will be no more than 10,000 sequences.

SAMPLE OUTPUT (file ariprog.out)

1 4

37 4

2 8

29 8

1 12

5 12

13 12

17 12

5 20

2 24

 

代码:

1 #include 
2 #include
3 #include
4 using namespace std; 5 bool a[125000+10]; 6 int n,m,maxn=0; 7 bool ok(int x,int y) 8 { 9 for(int i=0;i
maxn) return false;11 }12 return true;13 }14 int main()15 { 16 freopen("ariprog.in","r",stdin);17 freopen("ariprog.out","w",stdout);18 cin>>n>>m;19 for(int p=0;p<=m;p++){20 for(int q=0;q<=m;q++){21 a[p*p+q*q]=true;22 }23 }24 maxn=m*m+m*m;25 int y=0;26 int m=maxn/(n-1);27 for(int i=1;i<=m;i++){28 for(int j=0;j<=maxn-i*(n-1);j++){29 if(ok(j,i)){30 cout<
<<" "<
<

 

转载于:https://www.cnblogs.com/shenyw/p/5160141.html

你可能感兴趣的文章
Java学习笔记--字符串和文件IO
查看>>
转 Silverlight开发历程—(画刷与着色之线性渐变画刷)
查看>>
SQL语法(3)
查看>>
在js在添版本号
查看>>
sublime3
查看>>
Exception Type: IntegrityError 数据完整性错误
查看>>
Nuget:Newtonsoft.Json
查看>>
Hdu - 1002 - A + B Problem II
查看>>
Android设置Gmail邮箱
查看>>
js编写时间选择框
查看>>
JIRA
查看>>
小技巧——直接在目录中输入cmd然后就打开cmd命令窗口
查看>>
深浅拷贝(十四)
查看>>
HDU 6370(并查集)
查看>>
BZOJ 1207(dp)
查看>>
PE知识复习之PE的导入表
查看>>
HDU 2076 夹角有多大(题目已修改,注意读题)
查看>>
洛谷P3676 小清新数据结构题(动态点分治)
查看>>
九校联考-DL24凉心模拟Day2T1 锻造(forging)
查看>>
Attributes.Add用途与用法
查看>>