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-08-07 14:24:05

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

ACdream 1115 Salmon And Cat (找规律&amp;amp;&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>

codeforces Goodbye2018 C. New Year and the Permutation Concatenation 傻瓜解法找规律+打表

这是goodbye2018的D题,红包赛第一场的C题 是我打的第一场CF 不知道为什么每次一补到这一场我就要强调一遍这是我的第一场CF...... .... .... 真矫情 不过还挺有仪式感的,嗯嗯~ o( ̄▽ ̄)o 看题吧 这题是肯定有公式的,不然这么乱七八糟的真的很难找规律,而且题目的名字就是permutation concatenation 这个题目真的很坏,只给了n=3时ans=9:n=4时ans=56: 其实如果知道了n=5时,ans=395,问题就迎刃而解了 我的方法跟官方题解的不

组队赛#1 解题总结 ZOJ 3798 Abs Problem (找规律+打表)

Abs Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Alice and Bob is playing a game, and this time the game is all about the absolute value! Alice has N different positive integers, and each number is not greater than N.

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