Test instructions
The prime decomposition form of x-1 is obtained by giving a prime decomposition form of integer x.
First calculate the x, then the x-1 prime number decomposition on it, pay attention to the loss of the accuracy of the POW
Code:
#include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath > #include <climits> #include <algorithm> #include <vector> #include <string> #include < iostream> #include <sstream> #include <map> #include <set> #include <queue> #include < stack> #include <fstream> #include <numeric> #include <iomanip> #include <bitset> #include <list> #include <stdexcept> #include <functional> #include <utility> #include <ctime> Using namespace std, #define PB push_back#define MP make_pair#define REP (i,x,n) for (int i=x;i< (n); ++i) #define for (I,l, h) for (int i= (l); i<= (h), ++i) #define FORD (i,h,l) for (int i= (h); i>= (l); i) #define SZ (x) ((int) (x). Size ()) #define All (x) (x). Begin (), (x). End () #define RI (x) scanf ("%d", & (x)) #define RII (x, Y) scanf ("%d%d", & (X), & (Y)) # Define RIII (x, Y, z) scanf ("%d%d%d", & (X), & (Y), & (z)) #define DRI (x) int (x); scanf ("%d", &x) #define DRII (x, y) int X, y; scanf ("%d%d", &x, &y) #define DRIII (x, y, z) int x, y, Z; scanf ("%d%d%d", &x, &y, &z) #define OI (x) printf ("%d", x), #define RS (x) scanf ("%s", (x)) #define MS0 (x) memset ( (x), 0, sizeof ((x))) #define MS1 (x) memset ((x),-1, sizeof ((x))) #define LEN (x) strlen (x) #define F first#define S second#def Ine Swap (A, B) (a ^= B, b ^= A, a ^= b) #define Dpoint strcut node{int x, y} #define CMPD int cmp (const int &A,CONST int &B) {return a>b;}/* #ifdef HOME freopen ("In.txt", "R", stdin); #endif */const int MOD = 1e9+7;typedef vector<int> vi;typedef vector<string> vs;typedef vector<double> Vd;typedef Long Long ll;typedef pair<int,int> pii;//#define Homeint Scan () {int res = 0, ch, flag = 0;if (ch = getcha R ()) = = '-')//determine positive and negative flag = 1;else if (ch >= ' 0 ' && ch <= ' 9 ')//Get complete number res = CH-' 0 '; while ((ch = getchar ()) > = ' 0 ' && ch <= ' 9 ') res = res * + CH-' 0 '; return flag? -res:res;}/*---------------------Do----------HACK-----ME--------------------*/int In[40000];char s[100000];int Prime[10000];int vis[40005];int ans[40005];void getprime () {int cnt=0; for (int i=2;i<=40000;i++) {if (!vis[i]) {prime[cnt++]=i; for (int j=0;j<cnt&&prime[j]<=40000/i;j++) {prime[prime[j]*i]=1; if (i%prime[j]==0) break; }}}}int Main () {getprime (); while (gets (s)) {if (s[0]== ' 0 ') break; int Len=strlen (s); int t=0; int cnt=0; REP (I,0,len) {if (s[i]== ') {in[cnt++]=t; t=0; Continue } t=t*10+s[i]-' 0 '; } in[cnt++]=t; int x=1; for (int i=0;i<cnt;i+=2) {x=x* () (POW (double) in[i], (double) in[i+1]) +0.05); } x-=1; int p= (int) sqrt ((double) x); int q=0; for (int i=2;i<=p;i++) {int tmp=0; if (x%i==0) {while (x%i==0) { x=x/i; tmp++; } ans[q++]=tmp; Ans[q++]=i; }} if (x!=1) {ans[q++]=1; Ans[q++]=x; } for (int i=q-1;i>0;i--) printf ("%d", ans[i]); printf ("%d\n", Ans[0]);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Prime factorization of integers POJ 1365