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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
#include <iostream> #include <math.h> #include <vector> #include <map> #include <sstream> #include <fstream> #define SIZE 46500 #define lld long long using namespace std; // sqrt of 2^31 is ~46400 vector<int> v; int prime[SIZE]; void PrimeGenerate() { double p = sqrt(SIZE)+4; for(int i=3;i<p;i+=2) { if(prime[i]==0) { for(int j=i+i;j<SIZE;j+=i) prime[j]=1; } } v.clear(); v.push_back(2); for(int j=3;j<SIZE;j++) { if(prime[j]==0 && j%2!=0) v.push_back(j); } } int main() { int m,cnt; lld a,n; map<int,int> mp; PrimeGenerate(); //cout<<prime[21471]<<"\n"; //ofstream out; //out.open("out.txt"); while(cin>>n) { cin>>m; //if(m==0 && n==0) //break; cnt=0; if(n>=m) { cout<<m<<" divides "<<n<<"!\n"; //out<<m<<" divides "<<n<<"!\n"; continue; } mp.clear(); lld tmp = m; int j=0; int f=0; while(tmp>=v[j]*v[j]) { if(tmp%v[j]==0) { tmp/=v[j]; if(v[j]>n) { f=1; break; } mp[v[j]]++; cnt++; j=-1; } j++; if(j==v.size()) break; } if(f) { //cout<<"1)\n"; cout<<m<<" does not divide "<<n<<"!\n"; //out<<m<<" does not divide "<<n<<"!\n"; continue; } if(tmp>1) { if(tmp>n) { //cout<<"2)\n"; cout<<m<<" does not divide "<<n<<"!\n"; //out<<m<<" does not divide "<<n<<"!\n"; continue; } mp[tmp]++; cnt++; } //cout<<mp.size()<<"\n"; for(map<int,int>::iterator ii=mp.begin();ii!=mp.end();++ii) { a = 1;//ii->first; int t=0;//=n/a; int add=0; //cout<<t<<" "<<a<<" "<<n<<"\n"; while(1) { a*=ii->first; add=n/a; t+=add; if(add==0) break; } if(t<ii->second) { f=1; break; } //cout<<ii->first<<" "<<ii->second<<"\n"; } if(f) { //cout<<"3)\n"; cout<<m<<" does not divide "<<n<<"!\n"; //out<<m<<" does not divide "<<n<<"!\n"; } else { cout<<m<<" divides "<<n<<"!\n"; //out<<m<<" divides "<<n<<"!\n"; } } //out.close(); return 0; } |