Misaki's Kiss again(hdu5175)
Posted SJY
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Misaki's Kiss again(hdu5175)相关的知识,希望对你有一定的参考价值。
Misaki‘s Kiss again
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1773 Accepted Submission(s): 459
After the Ferries Wheel, many friends hope to receive the Misaki‘s kiss again,so Misaki numbers them 1,2...N,if someone‘s number is M and satisfied the GC equals to N XOR M,he will be kissed again.
Please help Misaki to find all M.
Note that:
GC means the greatest common divisor of a and b.
A XOR B means A exclusive or B
Please help Misaki to find all M.
Note that:
GC means the greatest common divisor of a and b.
A XOR B means A exclusive or B
B
Input
There are multiple test cases.
For each testcase, contains a integets N
For each testcase, contains a integets N
Output
For each test case,
first line output Case #X:,
second line output k means the number of friends will get a kiss.
third line contains k number mean the friends‘ number, sort them in ascending and separated by a space between two numbers
first line output Case #X:,
second line output k means the number of friends will get a kiss.
third line contains k number mean the friends‘ number, sort them in ascending and separated by a space between two numbers
Sample Input
3
5
15
Sample Output
Case #1:
1
2
Case #2:
1
4
Case #3:
3
10 12 14
思路:gcd(n,m) = norm --->gcd(n,nork) = k;应为m 可以表示为nork的形式,所以,我们只要枚举n的因子k然后判断是否符合即可。
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 #include<math.h> 6 #include<queue> 7 #include<stdlib.h> 8 #include<set> 9 #include<vector> 10 using namespace std; 11 typedef long long LL; 12 LL ans[100000]; 13 LL gcd(LL n,LL m); 14 int main(void) 15 { 16 LL N; 17 int cn = 0; 18 while(scanf("%lld",&N)!=EOF) 19 { 20 cn++; 21 ans[0] = -1; 22 printf("Case #%d:\n",cn); 23 if(N == 1) 24 { 25 printf("0\n"); 26 printf("\n"); 27 } 28 else 29 { 30 int sum = 0; 31 LL i; 32 for(i = 1; i <= sqrt(N); i++) 33 { 34 if(N%i==0) 35 { 36 LL pp = gcd(N,(LL)(N/(LL)i-(LL)1)*(LL)(i)); 37 LL ac = N^((LL)(N/(LL)i-(LL)1)*(LL)(i)); 38 if((N/i-1>=1)&&pp == ac) 39 { 40 ans[sum++] = (LL)(N/(LL)i-(LL)1)*(LL)(i); 41 } 42 if(N/(LL)i!=i) 43 { 44 LL pp = gcd(N,(LL)(i-1)*(LL)(N/i)); 45 LL ac = (LL)(i-1)*(LL)(N/i)^N; 46 if(i-1>0&&ac == pp) 47 { 48 //printf("1\n"); 49 ans[sum++] = (LL)(i-1)*(LL)(N/i); 50 } 51 } 52 } 53 } 54 printf("%d\n",sum); 55 sort(ans,ans+sum); 56 if(sum>=1) 57 printf("%lld",ans[0]); 58 for(i = 1; i < sum; i++) 59 { 60 printf(" %lld",ans[i]); 61 } 62 printf("\n"); 63 } 64 } 65 return 0; 66 } 67 LL gcd(LL n,LL m) 68 { 69 if(m == 0) 70 return n; 71 else return gcd(m,n%m); 72 }
以上是关于Misaki's Kiss again(hdu5175)的主要内容,如果未能解决你的问题,请参考以下文章
HDU 5618 Jam's problem again (cdq分治+BIT)
HDU 5618:Jam's problem again(CDQ分治+树状数组处理三维偏序)
解决root@localhost's password:localhost:permission denied,please try again
问题root@localhost's password:localhost:permission denied,please try again