CF 84 div1 A
2013-07-23 09:23
309 查看
题目:109A - Lucky Sum of Digits
思路:扩展欧几里得
View Code
思路:扩展欧几里得
#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
相关文章推荐
- cf 301 div2
- CF Div211 (C)
- CF 171(div2)A
- CF 164(div2)
- 【CF】222 Div.1 B Preparing for the Contest
- cf-#189-div 2
- 【 题集 】 CF #277.5 (Div. 2) 更新ing...
- CF 143 div2 C
- CF 89 div2 A
- cf div_124_a(简单博弈)
- 20130805-codeforce 108-div2-CF训练
- CF# Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) C计算几何 + D 图论
- CF_137_div2_E_Decoding Genome 题解
- 【Author : DS】CF #140 非常好的一套CF题目,DIV1 的E题实在没辙
- cf_290(div2)A,B,C
- 【CF】Codeforces Round #124 (Div. 2) 197A Plate Game
- cf 127 div .1 Fragile Bridges(dp 好题)
- Kolya and Tandem Repeat - CF#253 (Div. 2)B (443B) 哈希或水题
- CF Codeforces Round #256 (Div. 2) D (448D) Multiplication Table
- CF Codeforces Round #257 (Div. 1) A (449A) Jzzhu and Chocolate