标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 513 Accepted Submission(s): 121
sqrt(n) 求出n的所有约数ei。
然后求出 a 符合: a^n == ei 。
再判断 a 跟 n 的 GCD 是否等于ei 即可。
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <vector> #include <map> #include <vector> #include <queue> using namespace std ; typedef long long LL ; typedef pair<int,int> pii; #define X first #define Y second const int N = 100010; LL n , e[N] , x[N] ; int aa[100] , bb[100] , res[100] ; inline LL gcd( LL a , LL b ) { return b == 0 ? a : gcd( b , a % b );} LL decode( LL a , LL b ) { int lena = 0 , lenb = 0 ; memset( aa , 0 , sizeof aa ); memset( bb , 0 , sizeof bb ); LL x = a ; while( x > 0 ) { aa[lena++] = x % 2 ; x /= 2 ; } x = b ; while( x > 0 ) { bb[lenb++] = x % 2 ; x /= 2 ; } LL ans = 0 ; for( int i = 0 ; i < lena ; ++i ) { if( bb[i] == 0 ) res[i] = aa[i]; else res[i] = aa[i]^1; if( res[i] ) ans += (1LL<<i); } return ans ; } void solve() { int tot = 0 , cnt = 0 ; for( LL i = 1 ; i * i <= n ; ++i ) { if( n % i == 0 ){ e[tot++] = i ; if( i != n/i ) e[tot++] = n/i ; } } for( int i = 0 ; i < tot ; ++i ) { LL tmp = decode( n , e[i] ); if( tmp < 1 || tmp > n || tmp < e[i] || gcd( n , tmp ) != e[i] ) continue ; x[cnt++] = tmp ; } sort( x , x + cnt ); printf("%d\n",cnt); for( int i = 0 ; i < cnt ; ++i ) { printf("%I64d",x[i]); if( i < cnt -1 ) printf(" "); } puts(""); } int main () { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL int _ , cas =1 ; while( scanf("%I64d",&n) != EOF ) { printf("Case #%d:\n",cas++); solve(); } }
标签:
原文地址:http://www.cnblogs.com/hlmark/p/4292843.html