2018ccpc网络选拔赛 杭电

Find Integer 

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0
Special Judge

 

Problem Description

people in USSS love math very much, and there is a famous math problem .

give you two integers n,a,you are required to find 2 integers b,c such that an+bn=cn.

 

 

Input

one line contains one integer T;(1≤T≤1000000)

next T lines contains two integers n,a;(0≤n≤1000,000,000,3≤a≤40000)

 

 

Output

print two integers b,c if b,c exits;(1≤b,c≤1000,000,000);

else print two integers -1 -1 instead.

 

 

Sample Input

 

1 2 3

 

 

Sample Output

 

4 5

 

就是费马大定理,>2不存在,=0不存在,=1很好算,=2用费马大定理奇偶数列法则求解

若a为奇数,则 a = 2n + 1 ,c = n ^ 2 + (n + 1) ^ 2 ,b = c - 1;

若a为偶数,则 a = 2n + 2 ,c = 1 + (n + 1) ^ 2 ,b = c - 2;

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
typedef  long long ll;
int main(){
    int t;
    scanf("%d",&t);
    int n;
    ll a;
    while(t--){
        scanf("%d%lld",&n,&a);
        if(n==0 || n>2){
            printf("-1 -1\n");
            continue;
        }
        if(n==1){
            printf("1 %lld\n",a+1);
            continue;
        }
        ll b,c;
        if(a%2==0){
            ll k = (a - 2) / 2;
            c = 1 + (k + 1) * (k + 1);
            b = c - 2;
        }
        else{
            ll k = (a - 1) / 2;
            c = k * k + (k + 1) * (k + 1);
            b = c - 1;
        }
        printf("%lld %lld\n",b,c);
    }
    return 0;
}

 

Dream

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 509    Accepted Submission(s): 3
Special Judge

 

Problem Description

Freshmen frequently make an error in computing the power of a sum of real numbers, which usually origins from an incorrect equation (m+n)p=mp+np, where m,n,p are real numbers. Let's call it ``Beginner's Dream''.

For instance, (1+4)2=52=25, but 12+42=17≠25. Moreover, 9+16−−−−−√=25−−√=5, which does not equal 3+4=7. 

Fortunately, in some cases when p is a prime, the identity

(m+n)p=mp+np


holds true for every pair of non-negative integers m,n which are less than p, with appropriate definitions of addition and multiplication.

You are required to redefine the rules of addition and multiplication so as to make the beginner's dream realized.

Specifically, you need to create your custom addition and multiplication, so that when making calculation with your rules the equation (m+n)p=mp+np is a valid identity for all non-negative integers m,n less than p. Power is defined as

ap={1,ap−1⋅a,p=0p>0



Obviously there exists an extremely simple solution that makes all operation just produce zero. So an extra constraint should be satisfied that there exists an integer q(0<q<p) to make the set {qk|0<k<p,k∈Z} equal to {k|0<k<p,k∈Z}. What's more, the set of non-negative integers less than p ought to be closed under the operation of your definitions.

Hint


Hint for sample input and output:
From the table we get 0+1=1, and thus (0+1)2=12=1⋅1=1. On the other hand, 02=0⋅0=0, 12=1⋅1=1, 02+12=0+1=1.
They are the same.

 

 

Input

The first line of the input contains an positive integer T(T≤30) indicating the number of test cases.

For every case, there is only one line contains an integer p(p<210), described in the problem description above. p is guranteed to be a prime.

 

 

Output

For each test case, you should print 2p lines of p integers.

The j-th(1≤j≤p) integer of i-th(1≤i≤p) line denotes the value of (i−1)+(j−1). The j-th(1≤j≤p) integer of (p+i)-th(1≤i≤p) line denotes the value of (i−1)⋅(j−1).

 

 

Sample Input

 

1 2

 

 

Sample Output

 

0 1 1 0 0 0 0 1

 

 

Source

2018中国大学生程序设计竞赛 - 网络选拔赛

 

坑死人的题,读题两个小时,结果

还是漏了条件。。。并没有A掉

题意:重新定义加法和乘法的定义,然后输出矩阵

因为p是质数,由费马小定理,对于 a \in Z,a^{p} \equiv a % p mod p

所以 (x + y) ^{p} \equiv (x + y) \equiv x^{p} + y^{p} mod p

所以重新定义加法为  ( x + y )% p

                     乘法为  ( x * y )% p

代码:

#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e6 + 10;
typedef long long ll;

int main() {
    int t, n;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j == 0) printf("%d", (i + j) % n);
                else printf(" %d", (i + j) % n);
            }
            printf("\n");
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (j == 0) printf("%d", (i * j) % n);
                else printf(" %d", (i * j) % n);
            }
            printf("\n");
        }
    }
    return 0;
}

先写两篇

还有,莫干山真有趣

转载于:https://www.cnblogs.com/renxiaomiao/p/9642654.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值