找平方数

Description

While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square.

Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.

题目网址: http://codeforces.com/problemset/problem/417/E

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100)  — the size of the table.

Output

Print the table that meets the condition: n lines containing m integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.

Sample Input

Input

1 1

Output

1

Input

1 2

Output

3 4
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

bool judge(int num)
{
    int k = sqrt(num);
    if(k*k == num)
    return true;
    return false;
}

int main()
{
    int n,m;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        int a,b,c,d;
        int flag = 0;
        for(a=1;a<=100;a++)
        for(b=1;b<=100;b++)
        for(c=1;c<=100;c++)
        for(d=1;d<=100;d++)
        if(judge(a*a*(m-1)+b*b)&&
           judge(a*a*(n-1)+c*c)&&
           judge(c*c*(m-1)+d*d)&&
           judge(b*b*(n-1)+d*d))
        goto endw;

        endw:;
        for(int i=1;i<=n-1;i++)
        {
            for(int j=1;j<=m-1;j++)
            printf("%d ",a);
            printf("%d\n",b);
        }
        for(int i=1;i<=m-1;i++)
        printf("%d ",c);
        printf("%d\n",d);
    }
    return 0;
}
时间: 2025-01-02 15:15:55

找平方数的相关文章

Project Euler 98:Anagramic squares 重排平方数

Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively, we form a square number: 1296 = 362. What is remarkable is that, by using the same digital substitutions, the anagram, RACE, also forms a square num

sicily-2499 平方数

题目分析: 一个数可以表示成四种状态,所以可以用一个状态数组来存放该数由几个数的平方和表示.1.表示该数本身是完全平方.2.表示该数是由两个平方和3.表示三个.4.表示4个.一次遍历找出本身是完全平方的数,二次遍历找出后两种情况. #include <iostream> #include <map> using namespace std; const int N = 60001; int main() { int s[60001] = {0}; int t,n; for(int

排它平方数

第四届蓝桥杯C/C++ A组第二题,题目如下: 小明正看着 203879 这个数字发呆.原来,203879 * 203879 = 41566646641.这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字.具有这样特点的6位数还有一个,请你找出它! 再归纳一下筛选要求: 1. 6位正整数 2. 每个数位上的数字不同 3. 其平方数的每个数位不含原数字的任何组成数位 首先把代码贴上来吧: 1 #include<e

蓝桥杯-排他平方数

题目标题: 排它平方数 小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字. 具有这样特点的6位数还有一个,请你找出它! 再归纳一下筛选要求: 1. 6位正整数 2. 每个数位上的数字不同 3. 其平方数的每个数位不含原数字的任何组成数位 答案是一个6位的正整数. 请通过浏览器提交答案. 注意:只提交另一

2013第四届蓝桥杯 C/C++本科A组 排它平方数(2个数相乘为大数,大数位标记的方法)

小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢?仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字. 具有这样特点的6位数还有一个,请你找出它! 再归纳一下筛选要求: 1. 6位正整数 2. 每个数位上的数字不同 3. 其平方数的每个数位不含原数字的任何组成数位 答案是一个6位的正整数. 请通过浏览器提交答案. 注意:只提交另一6位数,题中已经给出的这

排他平方数

小明正看着 203879 这个数字发呆. 原来,203879 * 203879 = 41566646641 这有什么神奇呢? 仔细观察,203879 是个6位数,并且它的每个数位上的数字都是不同的,并且它平方后的所有数位上都不出现组成它自身的数字. 具有这样特点的6位数还有一个,请你找出它! 再归纳一下筛选要求: 1. 6位正整数 2. 每个数位上的数字不同 3. 其平方数的每个数位不含原数字的任何组成数位 分析:直接暴力枚举... 1 #include<iostream> 2 #includ

C语言(7)--高精度加法、减法、乘法、今天是星期几、四位平方数、候选人选票问题

1.高精度加法.减法.乘法 #include <stdio.h> #include <string.h> #include <malloc.h> void plus(char *a,char *b,char *c);//自定义高精度加法函数 void sub(char *a,char *b,char *c);//自定义高精度减法函数 void multiply(char *a,char *b,char *c);//自定义高精度乘法函数 int main() { char

2015年百度之星初赛(1) --- B 找连续数

找连续数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 179    Accepted Submission(s): 65 Problem Description 小度熊拿到了一个无序的数组,对于这个数组,小度熊想知道是否能找到一个k 的区间,里面的 k 个数字排完序后是连续的. 现在小度熊增加题目难度,他不想知道是否有这样的 k 的区

洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares

P1206 [USACO1.2]回文平方数 Palindromic Squares 271通过 501提交 题目提供者该用户不存在 标签USACO 难度普及- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 回文数是指从左向右念和从右向左念都一样的数.如12321就是一个典型的回文数. 给定一个进制B(2<=B<=20,由十进制表示),输出所有的大于等于1小于等于300(十进制下)且它的平方用B进制表示时是回文数的数.用’A’,’B’……表示10,11等等 输入输出格式 输入格式: 共