当前位置: 代码迷 >> 综合 >> C - Cocoa Coalition
  详细解决方案

C - Cocoa Coalition

热度:95   发布时间:2024-02-27 04:39:25.0

题目链接:https://vjudge.net/problem/Kattis-cocoacoalition
只有切1刀、2刀、3刀这三种情况

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;int main()
{
    long long int n,m,a;cin>>n>>m>>a;if(n>m) swap(n,m);if(a%n==0||a%m==0){
    cout<<1<<endl;return 0;}for(int i=1;i<=sqrt(a);i++){
    if(a%i==0){
    long long int l1=i,l2=a/i;if(l1>l2)swap(l1,l2);if(l1<=n&&l2<=m){
    cout<<2<<endl;return 0;}}}a=n*m-a;for(int i=1;i<=sqrt(a);i++){
    if(a%i==0){
    long long int l1=i,l2=a/i;if(l1>l2)swap(l1,l2);if(l1<=n&&l2<=m){
    cout<<2<<endl;return 0;}}}cout<<3<<endl;return 0;
}