ACdream 1115 Salmon And Cat (找规律&&打表)

题目链接:传送门

题意:

一个数被觉得是一个完美的数,仅仅要须要满足下面的两个条件之中的一个

1)x = 1 or 3

2)x = 2 + a*b + 2*a + 2*b; a。b都是完美的数。

分析:

x + 2 = (a + 2)*(b + 2)

因为x1=1,x2=3。全部的数都是由着两个数衍生而来。那么我们就可

以得出一个结论了。一个数x假设是完美的数。那么x = 3^p*5^q;

因此代码例如以下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main(){
    int n;
    while(~scanf("%d",&n)){
        n+=2;
        while(n%3==0) n/=3;
        while(n%5==0) n/=5;
        if(n!=1) puts("No");
        else puts("Yes");
    }
    return 0;
}

还能够打表把1e9以内的全部完美数打出来。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <map>
using namespace std;

typedef long long LL;

LL a[140]={1,3,7,13,23,25,43,73,79,123,133,223,241,373,403,623,673,727,1123,1213,1873,2023,2185,3123,3373,3643,5623,6073,6559,9373,10123,10933,15623,16873,18223,19681,28123,30373,32803,46873,50623,54673,59047,78123,84373,91123,98413,140623,151873,164023,177145,234373,253123,273373,295243,390623,421873,455623,492073,531439,703123,759373,820123,885733,1171873,1265623,1366873,1476223,1594321,1953123,2109373,2278123,2460373,2657203,3515623,3796873,4100623,4428673,4782967,5859373,6328123,6834373,7381123,7971613,9765623,10546873,11390623,12301873,13286023,14348905,17578123,18984373,20503123,22143373,23914843,29296873,31640623,34171873,36905623,39858073,43046719,48828123,52734373,56953123,61509373,66430123,71744533,87890623,94921873,102515623,110716873,119574223,129140161,146484373,158203123,170859373,184528123,199290373,215233603,244140623,263671873,284765623,307546873,332150623,358722673,387420487,439453123,474609373,512578123,553584373,597871123,645700813,732421873,791015623,854296873,922640623,996451873,
};

int main(){
    int n;
    while(~scanf("%d",&n)){
        int ans = 0;
        for(int i=0;i<137;i++)
            if(a[i]==n) ans = 1;
        if(ans) puts("Yes");
        else puts("No");
    }
    return 0;
}
时间: 2024-12-19 02:08:02

ACdream 1115 Salmon And Cat (找规律&amp;&amp;打表)的相关文章

ACdream 1115 Salmon And Cat (找规律&amp;&amp;打表)

题目链接:传送门 题意: 一个数被认为是一个完美的数,只要需要满足以下的两个条件之一 1)x = 1 or 3 2)x = 2 + a*b + 2*a + 2*b; a,b都是完美的数. 分析: x + 2 = (a + 2)*(b + 2) 由于x1=1,x2=3,所有的数都是由着两个数衍生而来.那么我们就可 以得出一个结论了,一个数x如果是完美的数,那么x = 3^p*5^q; 因此代码如下: #include <iostream> #include <cstdio> #inc

luogu1775 古代人的难题 打表找规律

题目大意:给出一正整数k,求满足(x^2-x*y-y^2)^2=1且x,y∈[1,k]且x^2+y^2最大的正整数x,y. 既然x,y的范围给出来了,我们便有了暴力解法.因此,本题最适合打表找规律了! 打表代码: #include <cstdio> using namespace std; int main() { printf("k\tx\ty\n"); for (long long k = 1; k <= 100; k++) { long long ansX =

Acdream 1115——找规律——Salmon And Cat

Math is very important, for those who are also in school, make sure you will learn more about math. Salmon and Cat are good friends.Today Salmon ask Cat to help her judge whether a number is perfect or not. Perfect number is a kind of number defined

ACdream原创群赛(13)のwuyiqi退役专场 H Salmon And Cat

H 首先是要姿势正确! 注意完美数的生成机: 2+2a+2b+ab ab都是完美数 假设生成完美数c c = 2 + 2a + 2b + ab c + 2 = ab+2a+2b+4 c + 2 = (a + 2)(b + 2) 然后一开始只有两个完美数1和3. 所以所有的完美数只有质因数分解之后都是类似于 N = (3 ^ x) * (5 ^ y) 但是5不是完美数. 然后就没事了... /**** *COPYRIGHT NOTICE *Copyright (c) 2014 *All right

Acdream 1210 Chinese Girls&#39; Amusement(大数模板运算 + 找规律)

传送门 Chinese Girls' Amusement Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description You must have heard that the Chinese culture is quite different from that of Europe or Rus

ACdream 1213 Matrix Multiplication【水题 、 找规律】

Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) 链接:http://acdream.info/problem?pid=1213 Problem Description Let us consider undirected graph G = {V; E} which has N vertices and M edges. Incidence

acdream 1210 Chinese Girls&#39; Amusement (打表找规律)

题意:有n个女孩围成一个圈从第1号女孩开始有一个球,可以往编号大的抛去(像传绣球一样绕着环来传),每次必须抛给左边第k个人,比如1号会抛给1+k号女孩.给出女孩的人数,如果他们都每个人都想要碰到球一次,那么这个k应该是多少(满足 1 ≤ K ≤ N/2 且 k必须尽量大)?   例如:n=7,那么1号开始拿球,抛球的顺序是 1, 4, 7, 3, 6, 2, 5, 1.  当球重新回到1女孩手中时,每个人刚好只玩了一次.注:这个数字相当大(3 ≤ N ≤ 102000) 思路: 方法(1): 暴

Acdream 1416 Crazy Nim(简单博弈找规律)

传送门 Crazy Nim Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description Alice and Bob like to play crazy nim. The game proceeds as follows. There are several stones arranged in

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4