1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
#include <iostream> #include <string> #include <stdio.h> #include <math.h> #include <vector> #include <stdlib.h> #define SIZE 2800001 #define ull unsigned long long using namespace std; int prime[1700]; ull arr [SIZE];//[10000001+5]; vector<int> v; void primeGenerator() { double p = sqrt(1700); for(int i=3;i<p;i+=2) { for(int j=i+i;j<1700;j+=i) { prime[j]=1; } } v.push_back(2); for(int i=3;i<1700;i++) { if(prime[i]==0 && i%2!=0) { v.push_back(i); } } } void factorize() { int tmp; arr[0]=1; arr[1]=0; arr[2]=1; for(int i=3;i<SIZE;i++) { tmp = i; arr[i]=0; int j=0; while(tmp>=(v[j]*v[j])) { if(tmp%v[j]==0) { tmp/=v[j]; arr[i]++; j=-1; } j++; if(j==v.size()) break; } //cout<<tmp<<"\n"; if(tmp>1) arr[i]++; arr[i]+=arr[i-1]; } } int main() { int n,kase=1; int mid; int high; int low; for(int i=0;i<1700;i++) { prime[i]=0; } primeGenerator(); factorize(); while(cin>>n) { if(n<0) break; if(n==0) { cout<<"Case "<<kase++<<": 0!\n"; continue; } mid=SIZE/2; high=SIZE; low=0; //binary search while((high-low)>1) { mid=(high+low)/2; if(arr[mid]<n) low=mid; else high = mid; } if(arr[low]==n) cout<<"Case "<<kase++<<": "<<low<<"!\n"; else if(arr[high]==n) cout<<"Case "<<kase++<<": "<<high<<"!\n"; else cout<<"Case "<<kase++<<": Not possible.\n"; } return 0; } |