]]>POJ 1006 Biorhythms 涓浗鍓╀綑瀹氱悊http://www.shnenglu.com/vontroy/archive/2010/10/02/128347.htmlVontroyVontroySat, 02 Oct 2010 12:18:00 GMThttp://www.shnenglu.com/vontroy/archive/2010/10/02/128347.htmlhttp://www.shnenglu.com/vontroy/comments/128347.htmlhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128347.html#Feedback0http://www.shnenglu.com/vontroy/comments/commentRss/128347.htmlhttp://www.shnenglu.com/vontroy/services/trackbacks/128347.html/**//*************************************** 姣旇緝緇忓吀鐨勪腑鍥藉墿浣欏畾鐞唦~ 浣?3×28琚?3闄や綑1錛岀敤33×28×6=5544 浣?3×33琚?8闄や綑1錛岀敤23×33×19=14421 浣?3×28琚?3闄や綑1錛岀敤23×28×2=1288 錛?544×p+14421×e+1288×i錛?錛?3×28×33錛?n+d n=錛?544×p+14421×e+1288×i-d錛?錛?3×28×33錛?br />****************************************/ #include <iostream> #include <cstdio> using std :: cin; using std :: cout; using std :: endl; int get__( int a, int b, int c ) { int ans; int cnt =1; while( ( a * b * cnt ) % c !=1 ) { cnt++; } return a * b * cnt; } int main() { int _p = get__( 28, 33, 23 ); int _e = get__( 23, 33, 28 ); int _i = get__( 23, 28, 33 ); int p, e, i, d; int cas =1; while( cin >> p >> e >> i >> d ) { if( p == e && e == i && i == d && d ==-1 ) break; int ans = ( _p * p + _e * e + _i * i - d ) % ( 23*28*33 ); if( ans <=0 ) printf("Case %d: the next triple peak occurs in %d days.\n", cas++, 21252- ans -2* d); else printf("Case %d: the next triple peak occurs in %d days.\n", cas++, ans); } return0; }
]]>HDU 1788 Chinese remainder theorem againhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128310.htmlVontroyVontroySat, 02 Oct 2010 06:58:00 GMThttp://www.shnenglu.com/vontroy/archive/2010/10/02/128310.htmlhttp://www.shnenglu.com/vontroy/comments/128310.htmlhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128310.html#Feedback0http://www.shnenglu.com/vontroy/comments/commentRss/128310.htmlhttp://www.shnenglu.com/vontroy/services/trackbacks/128310.html/**//********************************** N % MI = MI - a 鍥犱負 a < MI 鍘熷紡絳変環浜?nbsp;(N + a) % MI = 0 鎵浠ユ棰樹負姹?nbsp;M0 鍒?nbsp;MI 鐨勬渶灝忓叕鍊嶆暟 (娉ㄦ剰綺懼害闂,鐢╛_int64) ***********************************/ #include <iostream> #include <cstdio> usingnamespace std; __int64 gcd( __int64 a, __int64 b ) { if( b ==0 ) return a; return gcd( b, a % b ); } __int64 lcm( __int64 a, __int64 b ) { return a * b / gcd( a, b ); } int main() { int n, k; int tmp; __int64 ans; while( cin >> n >> k, n || k ) { ans =1; for( int i =0; i < n; i++ ) { cin >> tmp; ans = lcm( ans, tmp ); } cout << ans - k << endl; } return0; }
]]>HDU 1018 Big Numberhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128302.htmlVontroyVontroySat, 02 Oct 2010 06:22:00 GMThttp://www.shnenglu.com/vontroy/archive/2010/10/02/128302.htmlhttp://www.shnenglu.com/vontroy/comments/128302.htmlhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128302.html#Feedback0http://www.shnenglu.com/vontroy/comments/commentRss/128302.htmlhttp://www.shnenglu.com/vontroy/services/trackbacks/128302.html鏂壒鐏靛叕寮?/strong>鏄竴鏉$敤鏉ュ彇n闃朵箻榪戜技鍊?/font>鐨?font color="#000000">鏁板鍏紡銆備竴鑸潵璇達紝褰搉寰堝ぇ鐨勬椂鍊欙紝n闃朵箻鐨勮綆楅噺鍗佸垎澶э紝鎵浠ユ柉鐗圭伒鍏紡鍗佸垎濂界敤錛岃屼笖錛屽嵆浣垮湪
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8759 Accepted Submission(s): 3879
Problem Description
In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of digits in the factorial of the number.
Input
Input consists of several lines of integer numbers. The first line contains an integer n, which is the number of cases to be tested, followed by n lines, one integer 1 ≤ n ≤ 107 on each line.
Output
The output contains the number of digits in the factorial of the integers appearing in the input.
Sample Input
2
10
20
Sample Output
7
19
//log10(n!)=(0.5*log(2*PI*n)+n*log(n)-n)/log(10) #include <iostream> #include <cstdio> #include <cmath> constdouble PI =3.1415926; int main() { int n; int tmp; while( ~scanf("%d", &n ) ) { for( int i =0; i < n; i++ ) { scanf("%d", &tmp); double cnt =1; cnt += (0.5* log( 2* PI * tmp ) + tmp * log( tmp ) - tmp ) / log(10); printf("%d\n", (int)(cnt)); } } return0; }
]]>姹備袱涓垨N涓暟鐨勬渶澶у叕綰︽暟(gcd)鍜屾渶灝忓叕鍊嶆暟(lcm)鐨勮緝浼樼畻娉?/title>http://www.shnenglu.com/vontroy/archive/2010/10/02/128301.htmlVontroyVontroySat, 02 Oct 2010 06:20:00 GMThttp://www.shnenglu.com/vontroy/archive/2010/10/02/128301.htmlhttp://www.shnenglu.com/vontroy/comments/128301.htmlhttp://www.shnenglu.com/vontroy/archive/2010/10/02/128301.html#Feedback1http://www.shnenglu.com/vontroy/comments/commentRss/128301.htmlhttp://www.shnenglu.com/vontroy/services/trackbacks/128301.html姹備袱涓垨N涓暟鐨勬渶澶у叕綰︽暟(gcd)鍜屾渶灝忓叕鍊嶆暟(lcm)鐨勮緝浼樼畻娉?/span>
//涓や釜鏁扮殑鏈澶у叕綰︽暟--嬈у嚑閲屽緱綆楁硶 int gcd(int a, int b) { if (a < b) swap(a, b); if (b ==0) return a; else return gcd(b, a%b); } //n涓暟鐨勬渶澶у叕綰︽暟綆楁硶 //璇存槑: //鎶妌涓暟淇濆瓨涓轟竴涓暟緇?br> //鍙傛暟涓烘暟緇勭殑鎸囬拡鍜屾暟緇勭殑澶у皬(闇瑕佽綆楃殑鏁扮殑涓暟) //鐒跺悗鍏堟眰鍑篻cd(a[0],a[1]), 鐒跺悗灝嗘墍姹傜殑gcd涓庢暟緇勭殑涓嬩竴涓厓绱犱綔涓篻cd鐨勫弬鏁扮戶緇眰gcd //榪欐牱灝變駭鐢熶竴涓掑綊鐨勬眰ngcd鐨勭畻娉?/span> int ngcd(int*a, int n) { if (n ==1) return*a; return gcd(a[n-1], ngcd(a, n-1)); } //涓や釜鏁扮殑鏈灝忓叕鍊嶆暟(lcm)綆楁硶 //lcm(a, b) = a*b/gcd(a, b) int lcm(int a, int b) { return a*b/gcd(a, b); } //n涓暟鐨勬渶灝忓叕鍊嶆暟綆楁硶 //綆楁硶榪囩▼鍜宯涓暟鐨勬渶澶у叕綰︽暟姹傛硶綾諱技 //姹傚嚭澶翠袱涓殑鏈灝忓叕鍊嶆暟,鍐嶅皢嬈哄拰澶т笁涓暟姹傛渶灝忓叕鍊嶆暟鐩村埌鏁扮粍鏈熬 //榪欐牱浜х敓涓涓掑綊鐨勬眰nlcm鐨勭畻娉?/span> int nlcm(int*a, int n) { if (n ==1) return*a; else return lcm(a[n-1], nlcm(a, n-1)); }