
GCJ-Round 1C 2014- A. Part Elf.
This program is correct for the small and large input.
It's a for everybody to learn and discuss.
If there is any mistake or comment, please let me know. :D
此乃 GCJ-Round 1C 2014- A. Part Elf.的AC code!
這份程式在小跟大的測試資料都是正確的!
歡迎一同討論學習,如有錯誤與任何建議請留言 : )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Google Code Jam Round 1C 2014 - Problem A. Part Elf | |
//https://code.google.com/codejam | |
#include<stdio.h> | |
#include<stdlib.h> | |
#include<string.h> | |
#include<iostream> | |
using namespace std; | |
bool check(long long int n) | |
{ | |
while(n%2 == 0) | |
n /= 2; | |
if(n != 1) | |
return true; | |
return false; | |
} | |
long long int GCD(long long int a, long long int b) | |
{ | |
if(a < b) | |
return GCD(b, a); | |
if(b == 0) | |
return a; | |
return GCD(b, a%b); | |
} | |
int main() | |
{ | |
freopen ("a_output.txt","w",stdout); | |
int T, ans; | |
char c; | |
long long int P, Q; | |
scanf("%d", &T); | |
for(int testCase = 1; testCase <= T; testCase++) | |
{ | |
scanf("%lld%c%lld", &P, &c, &Q); | |
//printf("%d %d\n", P, Q); | |
int ans = 0; | |
printf("Case #%d: ", testCase); | |
long long gcd = GCD(P, Q); | |
P = P/gcd; | |
Q = Q/gcd; | |
if(check(Q)) | |
{ | |
printf("impossible\n"); | |
continue; | |
} | |
while(1) | |
{ | |
ans ++; | |
P *= 2; | |
if(P >= Q) | |
break; | |
} | |
printf("%d\n", ans); | |
} | |
return 0; | |
} |
歡迎使用與分享任何內容,但請記得標示此部落格為出處。(http://autekroy.blogspot.tw/) 如果有發現任何的錯誤與建議請留言或跟我連絡。 : )
沒有留言:
張貼留言
請留下您的任何想法或建議!
Please leave any thought or comment!