Ultraviolet-11752 the super powers

Source: Internet
Author: User

We all know the super powers ofthis world and how they manage to get advantages in political warfare or ev1_other sectors. but this is not a political platform and so we will talkabout a different kind of super powers-the super power numbers ". A positivenumber is said to be super power when it is the power of at least two differentpositive integers. for example 64 is a super power as 64 = 82 and 64 = 43.you have to write a program that lists all super powers within 1 and 264-1 (random SIVE ).

Input
This program has noinput.

Output

Print all thesuper power numbers within 1 and 2 ^ 64-1. Each line contains a single superpower number and the numbers are printed in ascending order.

Sample Input Partial judge output
No input for this problem 

1

16
64

81
256

512
.
.
.

Problemsetter: Shahriar Manzoor, special thanks: sohelhafiz

If a number is a super power, it must at least be the power of two different positive integers and output all values from small to large.

Idea: If this number is a super power, its index must be a combination. If we enumerate the base number first, the size is 1 ~ (1 <16), and then find the number in the range of 2 ^ 64-1

#include <iostream>#include <cstring>#include <algorithm>#include <set>#include <cstdio>#include <cmath>typedef unsigned long long ll;using namespace std;const int maxn = 100;int vis[maxn];int main() {memset(vis, 0, sizeof(vis));for (int i = 2; i < 100; i++)if (!vis[i]) {for (int j = i*i; j < 100; j += i)vis[j] = 1;}set<ll> ans;for (ll i = 2; i < (1<<16); i++) {int top = ceil(64*log10(2)/log10(i));ll tmp = 1;for (int j = 1; j < top; j++) {tmp *= i;if (vis[j])ans.insert(tmp);}}printf("1\n");set<ll>::iterator ite = ans.begin();while (ite != ans.end()) cout << *ite++ << endl;return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.