CF Round #528 Div. 2
阿新 • • 發佈:2019-01-07
A
B - Div Times Mod
題意:給出n,k 求 一個 使等式成立的最小正整數x
思路 : 令(x%k) = a 則 原式變為 (x-a)/k * a = n 這裡 a∈ (1,k)並且為n的因子
解出x來得到 x= n*k / a + a 求最小值即可。即 在a的定義域內找一個最靠近 sqrt (n*k)就是最小值
#include<bits/stdc++.h> using namespace std; int n,k,x,a,b,c,ans,ttt=0x3f3f3f3f,ad; int main() { scanf("%d%d",&n,&k); c=sqrt(k*n); for(int i=1; i<k; i++) { if(n%i==0) { if(abs(i-c)<ttt) { ttt=abs(i-c); ad=i; } } } ans=n*k/ad+ad; printf("%d\n",ans); return 0; }
C 模擬
#include<bits/stdc++.h> using namespace std; struct unt { int x,y; } coo[5]; bool cmp(unt a,unt b) { if(a.x == b.x) return a.y < b.y; return a.x < b.x; } int main() { int n = 3; int x,y,minx=1000,miny=1000,maxx=0,maxy=0; for(int i=0; i<3; i++) { cin>>x>>y; maxx = max(maxx,x); minx = min(minx,x); maxy = max(maxy,y); miny = min(miny,y); coo[i].x = x; coo[i].y = y; } sort(coo,coo+n,cmp); int ans = maxx - minx + (maxy - miny) + 1; cout<<ans<<endl; int tem = min(coo[0].y,min(coo[1].y,coo[2].y)); while(tem<=maxy) { cout<<coo[1].x<<' '<<tem<<endl; tem++; } tem = coo[0].x; while(tem<coo[1].x) { cout<<tem<<' '<<coo[0].y<<endl; tem++; } tem = coo[1].x+1; while(tem<=coo[2].x) { cout<<tem<<' '<<coo[2].y<<endl; tem++; } return 0; }