8.13
(被数论支配的恐惧)
(我飘了...dbq...正解太难了...暴力分对我也挺有好的...我不想写正解了...)
(就这样吧...)
T1-SZY 的神算(righttriangle)
题解:
注意有两种情况,所给的两条边 ,可能是两条直角边,也可能是一条直角边一条斜边
但是...如果两条边相等的话,就只可能是两条直角边了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define ll long long #define db double using namespace std; inline ll read() { ll sum = 0,p = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') p = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (sum *= 10) += ch - '0'; ch = getchar(); } return sum * p; } int main() { freopen("righttriangle.in","r",stdin); freopen("righttriangle.out","w",stdout); ll n = read(),m = read(); printf("%.13lf\n",(db)sqrt(n * n + m * m)); if(n != m) { if(n < m) swap(n,m); printf("%.13lf\n",(db)sqrt(n * n - m * m)); } return 0; }
T2-SZY 和贝尔数(bell)
题解:
我搞不懂,就按所给的递推式打了个表,于是...数组打表
正解是乘法矩阵+中国剩余定理
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define ll long long #define mod 95041567 using namespace std; inline int read() { int sum = 0,p = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') p = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (sum *= 10) += ch - '0'; ch = getchar(); } return sum * p; } int bel[1009] = {1,1,2,5,15,52,203,877,4140,21147,115975,678570,4213597,27644437,816188,52376607,25569777,83664947,58521367,41238267,66393230,44010570,24269368,65243549,30593854,76037701,88240771,38218614,38251537,16003483,94585219,88100886,46712942,80811365,30515924,35376864,21292729,82094381,61344190,19952738,78396064,60872948,36180002,6647501,56411961,29448686,76937985,65229046,92952796,33003924,5069299,5011395,42797938,52026508,12573945,45331783,58382906,52019798,90324020,37704740,6462275,60955832,61376440,89317675,29682837,33967624,46959432,92768742,55914473,20075493,9196522,31752518,58272322,41792692,67148641,90507671,92259971,62925358,87201700,59099733,66903688,5903351,16824027,21632020,24474239,63864393,10751424,93228611,50693372,46753084,80363452,43199264,20720100,70314277,38346882,67458687,4679394,71523183,40637086,39036292,72376368,18864144,64713619,8777330,80703929,10077278,31648377,27007366,9247217,51584839,23499379,11119736,92670570,28601891,38165206,73979494,9147320,83912774,69121308,65638689,78501313,18501391,84050299,1413408,23689632,74692233,3017722,56881982,60392191,10441791,94614442,25842168,50247586,19944928,19405635,5674303,58319769,12056109,66968019,77264505,43047702,25349371,81257491,45565439,63345317,91945689,21717860,31555071,52168979,18110097,62055443,15206476,64924479,92794804,2957198,41913381,59040298,3452052,86950159,60128845,53993343,73847831,75396160,91909440,70051258,3767190,94983501,90615592,84947887,42904126,62192291,41197952,60716353,11073425,16973870,23703322,73542357,3981257,38757372,83294798,9653002,51567352,27726757,54072612,3819146,79790777,52387901,64829068,33955954,74052552,7448801,82276506,82345898,39523786,75007806,64183834,47062500,44035175,82771086,83940234,41536280,54236457,72700804,85448936,57311109,75267798,85232745,37283971,37208446,1374967,44755200,53565772,33454719,37662034,65707230,78377,59962411,50018641,41155619,18540987,25262827,26934063,76622549,34243100,38625612,87486678,4679215,76778341,88913411,22281483,22009984,68901038,68483103,62682822,9618455,12509676,16014937,7921713,47118456,24481172,27635877,2281298,77486751,59877455,67194093,21931674,27943853,83606035,37877572,65121606,92205106,78147455,27231667,93452856,44507122,24194551,29987829,19135466,35504214,17871440,76572449,17998216,60846133,23005437,53394532,9770198,23372444,43279627,24192224,27967190,17945687,69661624,86815930,1463368,47724196,87293326,84887764,67270821,22510031,63848906,30148716,50489294,16219402,9085825,51335159,336536,94351343,52515997,14418544,10373167,78684202,77695226,21582420,14004819,92106398,23717416,49312769,33216525,18516589,41284180,77043325,40681495,44167902,31112942,81785893,68833390,78905407,83225993,61250839,67815264,10603964,69627089,45853322,3661120,80302710,6831063,20845662,45543251,9257057,55902784,41324840,25271159,12348190,30918701,9532112,53168195,24322613,7601984,18462209,35199479,29768007,25404805,62570100,36849834,87493281,27470946,86208323,60695277,948382,61507927,94022582,22424051,8884679,67080065,24003537,23000756,66275569,79426118,36571843,9820842,94734604,4763337,89930113,66967445,19603096,27131093,63515481,51549209,55052417,4709154,17925916,14348633,17473589,12206890,47975297,46501781,87996730,40772930,94459081,77965299,85385445,54695408,85664719,36827120,14884021,6030384,61797336,28855867,51617068,53260952,19057663,4005076,68316232,69517207,10097819,51923186,16950398,41244142,57797272,428036,51279349,88269353,88557554,62927731,22055442,71753086,19920713,87343647,22876510,83542637,79644668,40141875,68591965,17502372,32022731,44674665,9287258,75038627,65232219,32364649,36015445,86268763,52669819,93632554,42329931,31644105,89696997,59586068,14919101,18540999,3195485,13930440,20155573,53533872,32482410,6548333,31892035,5053702,44613586,51636567,2997130,19941247,42788067,20797580,37642400,26551021,1958214,36134649,72051781,34069932,51355049,22570910,67073576,25177685,46310826,22054523,88832177,88604440,39234423,42528251,49919762,33513796,82911385,60624960,15601983,86442546,84027945,26001559,33594098,52440271,75631640,42987782,5078800,7038082,14309496,55733118,70930162,37934329,66854037,41348980,76344058,49528804,36315310,92937260,73455492,37080490,23092561,14211511,76224142,71914470,19505509,73502429,83561275,32367276,26926062,76816884,1538347,59383595,71972345,12619208,13868438,19824313,78974264,43195405,90298553,73258306,17165669,25190500,50961795,7724205,73945187,84523822,77956443,67024410,53813059,80107622,12297798,16214741,42555409,14748929,49562477,15313041,55119739,22229532,16872845,2046702,75145677,38171755,54581030,46432413,42526085,94281972,7615301,35495653,53821478,4217045,49546786,50097737,63273841,80130343,37048426,83863262,28404242,34240700,32428507,91514324,87634458,33827923,39953026,40832550,63471337,65893961,1965839,1292786,61102519,62747223,34967372,89646204,40514654,59789922,48044574,7683757,8402978,72769243,65773902,70211572,60080701,18154792,66737875,48680305,17172459,44543994,40995094,93741321,57756397,94805683,39535601,68791490,21305668,55192069,14445520,92325258,72033671,17479875,48035609,8255919,70522480,84207649,10249727,41631806,10420406,46263628,15564013,1044010,14083570,386483,86114793,13466635,60396529,40094969,35574661,48620038,2143291,82857977,81047738,69356251,50150926,26733138,29346892,27231731,85306198,7925232,72284403,46906092,1309183,82621533,86222987,12986101,39483929,34501724,91399241,37059298,72021681,34494744,68246576,85276068,87497213,53880174,18326075,14948610,31988739,67828900,84524995,80039656,38899052,80145124,78717098,31895717,73978128,7913211,13951264,31909121,56939733,41055336,94436709,18822935,40681561,26754307,37294445,30741366,82534662,9963054,90358529,88479199,67154405,2471424,15252206,35567412,84747485,56707802,91791466,2607932,92578889,73622617,78053211,56579579,82891359,88195754,47383045,28882765,87743009,94550287,35912665,5676449,59500598,10379293,69075994,73525322,44876833,10888892,78283755,9855374,56463651,25837693,36896598,66165609,54186140,35922940,65916097,69729316,10816085,62096995,81867237,6091280,82230279,92771723,93098317,1019501,65210938,87104867,19977880,73234583,18588571,86487871,29282054,30476349,2226103,287632,23981022,1541424,86301272,40149207,57061185,73210036,49184997,23766904,17505312,13134468,29371639,70145327,40917574,47817433,541864,73959320,57827944,54295659,87668271,37946748,10037700,80443669,49457684,79129008,73858127,27567731,76493018,39942180,37736015,36304169,64889411,86612813,92729877,71264589,37734970,66609094,55807343,66386504,12824012,61918594,24763319,19853786,38228432,92675417,59753161,82691787,10548837,3960914,62466879,21197316,59466290,34084123,78302876,86181978,18833147,51508015,3962958,75808427,36496555,69436901,83084589,87761388,4175919,64053225,48253168,93954879,89502838,1842330,94359906,73702959,19025808,85557906,3391026,11718211,92119039,10595965,39141501,15075935,68715500,65645321,56716571,71668536,28112817,37119711,93635521,16567322,52859068,52562220,82129768,66338210,41213324,17050358,67677606,82710887,62321497,82898847,41155782,90247582,75419619,29847009,9793971,91065389,30613566,69042789,50505904,65288890,85644673,51287471,80158731,35380797,43927738,71079375,77568644,12774328,63362255,44492298,91271532,13745639,27253583,7756839,19150911,12436041,92068392,78882002,76089686,51835448,25823751,21403801,55674861,67590189,91723894,22241779,39183770,48922964,43543854,72582530,92892046,29481587,312110,89562644,93515308,9556583,91051135,24859440,44835418,64783742,82427524,79795323,91883211,42908602,88281426,93483753,9769580,93387960,27766505,15141089,45314140,31930571,82459611,13340569,70772379,32923675,32807651,85228291,1789989,37402628,13494937,33539661,67205985,86397112,18352229,23723361,82321035,83477383,55032137,49816223,71838858,4603347,50982948,76968815,1463491,26735016,60132395,30563786,57994073,86926726,58413507,2227563,11859263,3576110,90327952,52905623,4867724,67143304,7722512,30422438,45927986,33727352,46428500,62373290,21246377,64369674,29896957,55613196,27997837,9829237,82351576,76397937,8916880,65361585,69018784,36735504,58350449,39212435,84691198,65241499,1089948,48927720,4756012,65126110,94912461,56907937,66124158,56836249,73296224,40542056,36457640,45524493,87600564,57697763,10574801,6796071,67173499,19629387,92808113,47621772,1115957,74859855,29342953,89016051,39977340,33734282,81190296,27660178,60881904,63075161,68529471,71155514,25610535,72853100,42747870,18345527,9993323,43588844,61761942,37981869,43590469,74815739,27180635,88361929,33301216,59137110,19041786,86746993,20007621,84091632,22872972,63016107,30957403,26903734,38255275,66637825,84521576,50888813,1834834,93576848,38789981,19435582,50948359,25838199,41328380,27257269,14870187,19736646,46661648,79089658,36392628,56123705,79285371,26697153,46682143,58403674,89129181,24662120,36406252,55558275,60401209,14022709,80533243,12406736,80214810,73502066,55264652}; int main() { freopen("bell.in","r",stdin); freopen("bell.out","w",stdout); int t = read(),n; while(t--) { n = read(); printf("%d\n",bel[n]); } return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<string.h> int M=95041567; int MOD; struct matrix { int x[55][55]; int size; matrix() { memset(x,0,sizeof(x)); } friend matrix operator*(matrix a,matrix b) { matrix re; re.size=a.size; for(int i=1;i<=a.size;i++) { for(int j=1;j<=b.size;j++) { for(int k=1;k<=re.size;k++) { re.x[i][j]=(re.x[i][j]+a.x[i][k]*b.x[k][j])%MOD; } } } return re; } }; matrix quickpower(matrix x,int y) { matrix re=x; y--; while(y) { if(y&1) { re=re*x; } x=x*x; y>>=1; } return re; } int mod[5]={31,37,41,43,47}; int bell[5][55]; int c[5][55][55]; void init() { for(int k=0;k<5;k++) { MOD=mod[k]; for(int i=1;i<=50;i++) { c[k][i][0]=1; c[k][i][i]=1; } for(int i=2;i<=50;i++) { for(int j=1;j<i;j++) { c[k][i][j]=(c[k][i-1][j-1]+c[k][i-1][j])%MOD; } } bell[k][0]=1; bell[k][1]=1; for(int i=2;i<=50;i++) { bell[k][i]=0; for(int j=0;j<i;j++) { bell[k][i]=(bell[k][i]+c[k][i-1][j]*bell[k][j])%MOD; } } } } int cal(int n,int k) { MOD=mod[k]; matrix ori; ori.size=MOD; for(int i=1;i<MOD;i++) { ori.x[i][i+1]=1; } ori.x[MOD-1][1]=1; ori.x[MOD][1]=1; matrix tmp=quickpower(ori,n-MOD); int re=0; for(int i=1;i<=MOD;i++) { re=(re+bell[k][MOD-i+1]*tmp.x[i][1])%MOD; } return re; } int a[5]; int exgcd(int a,int b,int &x,int &y) { if(!b) { x=1; y=0; return a; } else { int re=exgcd(b,a%b,y,x); y-=a/b*x; return re; } } int CRT() { int re=0; int x,y; for(int i=0;i<5;i++) { int tmp=M/mod[i]; int ign=exgcd(mod[i],tmp,x,y); re=(re+y*tmp*a[i])%M; } return (re%M+M)%M; } int main() { freopen("bell.in","r",stdin); freopen("bell.out","w",stdout); int t; scanf("%d",&t); init(); while(t--) { int n; scanf("%d",&n); if(n<=50) { for(int i=0;i<5;i++) { a[i]=bell[i][n]; } printf("%d\n",CRT()); } else { for(int i=0;i<5;i++) { a[i]=cal(n,i); } printf("%d\n",CRT()); } } fclose(stdin); fclose(stdout); return 0; } //反正我是不会...
T3-SZY 找互质(coprime)
题解:
我暴力枚举1到1e9的数,挨个求gcd比较,得了30分
(如果和我一样懒得话,可以用库函数中的__gcd() (注意:gcd前面是两个下划线,不是一个))
正解是二分+容斥
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> #define ll long long using namespace std; inline int read() { int sum = 0,p = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') p = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (sum *= 10) += ch - '0'; ch = getchar(); } return sum * p; } int ans,tot; int gcd(int a,int b) { if(b == 0) return a; else return gcd(b,a % b); } int main() { freopen("coprime.in","r",stdin); freopen("coprime.out","w",stdout); int t = read(); for(int i = 1; i <= t; i++) { tot = 0; int n = read(),m = read(),k = read(); if(k == 1) ans = 1; else for(int j = 1; j <= 1e9; j++) if(__gcd(n,j) == 1 && __gcd(m,j) == 1) { tot++; if(tot == k) { ans = j; break; } } printf("Case %d: %d\n",i,ans); } return 0; }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> #include<algorithm> using namespace std; typedef long long ll; ll prime[5200]; ll cnt; bool not_prime[50005]; void get_prime() { for(ll i=2;i<=50000;i++) { if(!not_prime[i]) { prime[++cnt]=i; } for(ll j=1;j<=cnt&&i*prime[j]<=50000;j++) { not_prime[i*prime[j]]=1; if(i%prime[j]==0) { break; } } } } ll n; ll m; ll k; ll prime_factor[20]; ll num; ll tot; void get_prime_factor(ll x) { for(ll i=1;prime[i]*prime[i]<=x;i++) { if(x%prime[i]) { continue; } prime_factor[++num]=prime[i]; while(x%prime[i]==0) { x/=prime[i]; } } if(x!=1) { prime_factor[++num]=x; } } ll ans; void dfs(ll loc,ll used,ll product,ll limit) { if(loc>tot) { if(used&1) { ans-=limit/product; } else { ans+=limit/product; } return; } dfs(loc+1,used,product,limit); dfs(loc+1,used+1,product*prime_factor[loc],limit); } ll binary() { ll l=1; ll r=1ll<<62; ll mid; ll re; while(l<=r) { mid=(l+r)>>1; ans=0; dfs(1,0,1,mid); if(ans>=k) { re=mid; r=mid-1; } else { l=mid+1; } } return re; } int main() { freopen("coprime.in","r",stdin); freopen("coprime.out","w",stdout); get_prime(); ll t; scanf("%lld",&t); for(ll Case=1;Case<=t;Case++) { scanf("%lld%lld%lld",&n,&m,&k); printf("Case %lld: ",Case); num=0; get_prime_factor(n); get_prime_factor(m); sort(prime_factor+1,prime_factor+1+num); tot=0; for(ll i=1;i<=num;i++) { if(prime_factor[i]!=prime_factor[i-1]) { prime_factor[++tot]=prime_factor[i]; } } printf("%lld\n",binary()); } fclose(stdin); fclose(stdout); return 0; } //我依旧不会...