您的位置:首页 > 其它

CF 84 div1 A

2013-07-23 09:23 309 查看
题目:109A - Lucky Sum of Digits

思路:扩展欧几里得

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
long long exgcd(long long a,long long b,long long &x,long long &y)
{
if(b==0)
{
x=1;
y=0;
return a;
}
else
{
long long ans=exgcd(b,a%b,x,y);
long long t=x;
x=y;
y=t-a/b*y;
return ans;
}
}
int main()
{
long long n;
cin>>n;
long long x,y;
exgcd(4,7,x,y);
x*=n;
x%=7;
if(x<0)
x+=7;
y=n-4*x;
y/=7;
if(x<0||y<0)
{
cout<<-1<<endl;
return 0;
}
for(int i=1;i<=x;i++)
cout<<4;
for(int i=1;i<=y;i++)
cout<<7;
cout<<endl;
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: